1 package org
.asamk
.signal
.manager
.config
;
3 import org
.slf4j
.Logger
;
4 import org
.slf4j
.LoggerFactory
;
5 import org
.whispersystems
.signalservice
.api
.account
.AccountAttributes
;
6 import org
.whispersystems
.signalservice
.api
.push
.TrustStore
;
8 import java
.io
.IOException
;
9 import java
.security
.KeyStore
;
10 import java
.security
.KeyStoreException
;
11 import java
.security
.NoSuchAlgorithmException
;
12 import java
.security
.cert
.CertificateException
;
13 import java
.util
.List
;
15 import okhttp3
.Interceptor
;
17 public class ServiceConfig
{
19 private final static Logger logger
= LoggerFactory
.getLogger(ServiceConfig
.class);
21 public final static int PREKEY_MINIMUM_COUNT
= 20;
22 public final static int PREKEY_BATCH_SIZE
= 100;
23 public final static int MAX_ATTACHMENT_SIZE
= 150 * 1024 * 1024;
24 public final static long MAX_ENVELOPE_SIZE
= 0;
25 public final static long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE
= 10 * 1024 * 1024;
26 public final static boolean AUTOMATIC_NETWORK_RETRY
= true;
27 public final static int GROUP_MAX_SIZE
= 1001;
29 private final static KeyStore iasKeyStore
;
31 public static final AccountAttributes
.Capabilities capabilities
;
34 capabilities
= new AccountAttributes
.Capabilities(false,
46 TrustStore contactTrustStore
= new IasTrustStore();
48 var keyStore
= KeyStore
.getInstance("BKS");
49 keyStore
.load(contactTrustStore
.getKeyStoreInputStream(),
50 contactTrustStore
.getKeyStorePassword().toCharArray());
52 iasKeyStore
= keyStore
;
53 } catch (KeyStoreException
| CertificateException
| IOException
| NoSuchAlgorithmException e
) {
54 throw new AssertionError(e
);
58 public static boolean isSignalClientAvailable() {
61 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
62 } catch (Exception e
) {
63 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
66 } catch (UnsatisfiedLinkError e
) {
67 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
72 public static KeyStore
getIasKeyStore() {
76 public static ServiceEnvironmentConfig
getServiceEnvironmentConfig(
77 ServiceEnvironment serviceEnvironment
, String userAgent
79 final Interceptor userAgentInterceptor
= chain
-> chain
.proceed(chain
.request()
81 .header("User-Agent", userAgent
)
84 final var interceptors
= List
.of(userAgentInterceptor
);
86 return switch (serviceEnvironment
) {
87 case LIVE
-> new ServiceEnvironmentConfig(serviceEnvironment
,
88 LiveConfig
.createDefaultServiceConfiguration(interceptors
),
89 LiveConfig
.getUnidentifiedSenderTrustRoot(),
90 LiveConfig
.createKeyBackupConfig(),
91 LiveConfig
.createFallbackKeyBackupConfigs(),
92 LiveConfig
.getCdsMrenclave());
93 case STAGING
-> new ServiceEnvironmentConfig(serviceEnvironment
,
94 StagingConfig
.createDefaultServiceConfiguration(interceptors
),
95 StagingConfig
.getUnidentifiedSenderTrustRoot(),
96 StagingConfig
.createKeyBackupConfig(),
97 StagingConfig
.createFallbackKeyBackupConfigs(),
98 StagingConfig
.getCdsMrenclave());