Skip to content

Commit 612e3f2

Browse files
committed
Первоначальный коммит с изменениями для ГОСТ
1 parent 8b4326f commit 612e3f2

File tree

5 files changed

+915
-7
lines changed

5 files changed

+915
-7
lines changed

tls/src/main/java/org/bouncycastle/tls/CipherSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,5 @@ public static boolean isSCSV(int cipherSuite)
457457
public static final int TLS_GOSTR341112_256_WITH_KUZNYECHIK_CTR_OMAC = 0xC100;
458458
public static final int TLS_GOSTR341112_256_WITH_MAGMA_CTR_OMAC = 0xC101;
459459
public static final int TLS_GOSTR341112_256_WITH_28147_CNT_IMIT = 0xC102;
460+
public static final int TLS_GOSTR3410_2012_256_WITH_GOSTR3411_2012_256 = 0x0083; // или свой ID
460461
}

tls/src/main/java/org/bouncycastle/tls/DefaultTlsClient.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ public DefaultTlsClient(TlsCrypto crypto)
3535
super(crypto);
3636
}
3737

38-
protected int[] getSupportedCipherSuites()
39-
{
40-
return TlsUtils.getSupportedCipherSuites(getCrypto(), DEFAULT_CIPHER_SUITES);
41-
}
38+
// protected int[] getSupportedCipherSuites()
39+
// {
40+
// return TlsUtils.getSupportedCipherSuites(getCrypto(), DEFAULT_CIPHER_SUITES);
41+
// }
42+
43+
return new int[] {
44+
CipherSuite.TLS_GOSTR3410_2012_256_WITH_GOSTR3411_2012_256,
45+
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, // и т.д.
46+
};
47+
4248
}
49+
50+

tls/src/main/java/org/bouncycastle/tls/crypto/impl/bc/BcTlsCrypto.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
import org.bouncycastle.tls.crypto.impl.TlsNullCipher;
7171
import org.bouncycastle.util.Arrays;
7272

73+
import main.java.org.bouncycastle.tls.crypto.impl.bc.BcTlsGost2012Signer;
74+
7375
/**
7476
* Class for providing cryptographic services for TLS based on implementations in the BC light-weight API.
7577
* <p>
@@ -112,15 +114,31 @@ public TlsCertificate createCertificate(byte[] encoding)
112114
public TlsCertificate createCertificate(short type, byte[] encoding)
113115
throws IOException
114116
{
115-
switch (type)
116-
{
117+
switch (type)
118+
{
117119
case CertificateType.X509:
120+
{
121+
X509CertificateHolder certHolder = new X509CertificateHolder(encoding);
122+
SubjectPublicKeyInfo spki = certHolder.getSubjectPublicKeyInfo();
123+
ASN1ObjectIdentifier algOid = spki.getAlgorithm().getAlgorithm();
124+
125+
// Добавляем ГОСТ-обработку
126+
if (algOid.equals(new ASN1ObjectIdentifier("1.2.643.7.1.1.1.1")))
127+
{
128+
// Обработка ГОСТ-2012-256 сертификата
129+
return new BcTlsCertificate(this, encoding);
130+
}
131+
132+
// По умолчанию
118133
return new BcTlsCertificate(this, encoding);
134+
}
135+
119136
case CertificateType.RawPublicKey:
120137
return new BcTlsRawKeyCertificate(this, encoding);
138+
121139
default:
122140
throw new TlsFatalAlert(AlertDescription.internal_error);
123-
}
141+
}
124142
}
125143

126144
public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm)
@@ -131,6 +149,10 @@ public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAl
131149
case EncryptionAlgorithm.AES_128_CBC:
132150
case EncryptionAlgorithm.ARIA_128_CBC:
133151
case EncryptionAlgorithm.CAMELLIA_128_CBC:
152+
case CipherAlgorithm.kuznyechik: // <- добавить свой enum
153+
return new BcGOSTTlsCipher(cryptoParams, this, new KuznyechikEngine(), new GOST3413Mac());
154+
// ...
155+
134156
case EncryptionAlgorithm.SEED_CBC:
135157
case EncryptionAlgorithm.SM4_CBC:
136158
return createCipher_CBC(cryptoParams, encryptionAlgorithm, 16, macAlgorithm);
@@ -428,6 +450,8 @@ public boolean hasSignatureAlgorithm(short signatureAlgorithm)
428450
// TODO[RFC 9189]
429451
case SignatureAlgorithm.gostr34102012_256:
430452
case SignatureAlgorithm.gostr34102012_512:
453+
case SignatureAlgorithm.gostR3410_2012_256:
454+
return new BcTlsGost2012Signer(this, new ECGOST3410_2012Signer()); // пример
431455

432456
// TODO[RFC 8998]
433457
// case SignatureAlgorithm.sm2:

0 commit comments

Comments
 (0)