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,
47 TrustStore contactTrustStore
= new IasTrustStore();
49 var keyStore
= KeyStore
.getInstance("BKS");
50 keyStore
.load(contactTrustStore
.getKeyStoreInputStream(),
51 contactTrustStore
.getKeyStorePassword().toCharArray());
53 iasKeyStore
= keyStore
;
54 } catch (KeyStoreException
| CertificateException
| IOException
| NoSuchAlgorithmException e
) {
55 throw new AssertionError(e
);
59 public static boolean isSignalClientAvailable() {
62 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
63 } catch (Exception e
) {
64 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
67 } catch (UnsatisfiedLinkError e
) {
68 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
73 public static KeyStore
getIasKeyStore() {
77 public static ServiceEnvironmentConfig
getServiceEnvironmentConfig(
78 ServiceEnvironment serviceEnvironment
, String userAgent
80 final Interceptor userAgentInterceptor
= chain
-> chain
.proceed(chain
.request()
82 .header("User-Agent", userAgent
)
85 final var interceptors
= List
.of(userAgentInterceptor
);
87 return switch (serviceEnvironment
) {
88 case LIVE
-> new ServiceEnvironmentConfig(serviceEnvironment
,
89 LiveConfig
.createDefaultServiceConfiguration(interceptors
),
90 LiveConfig
.getUnidentifiedSenderTrustRoot(),
91 LiveConfig
.createKeyBackupConfig(),
92 LiveConfig
.createFallbackKeyBackupConfigs(),
93 LiveConfig
.getCdsMrenclave(),
94 LiveConfig
.getCdsiMrenclave());
95 case STAGING
-> new ServiceEnvironmentConfig(serviceEnvironment
,
96 StagingConfig
.createDefaultServiceConfiguration(interceptors
),
97 StagingConfig
.getUnidentifiedSenderTrustRoot(),
98 StagingConfig
.createKeyBackupConfig(),
99 StagingConfig
.createFallbackKeyBackupConfigs(),
100 StagingConfig
.getCdsMrenclave(),
101 StagingConfig
.getCdsiMrenclave());