7070import org .bouncycastle .tls .crypto .impl .TlsNullCipher ;
7171import 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