78 lines
3.6 KiB
Java
78 lines
3.6 KiB
Java
|
package org.bouncycastle.crypto.tls;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import org.bouncycastle.crypto.CryptoException;
|
||
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||
|
import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
|
||
|
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||
|
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class DefaultTlsSignerCredentials extends AbstractTlsSignerCredentials {
|
||
|
protected Certificate certificate;
|
||
|
protected TlsContext context;
|
||
|
protected AsymmetricKeyParameter privateKey;
|
||
|
protected SignatureAndHashAlgorithm signatureAndHashAlgorithm;
|
||
|
protected TlsSigner signer;
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.tls.AbstractTlsSignerCredentials, org.bouncycastle.crypto.tls.TlsSignerCredentials
|
||
|
public SignatureAndHashAlgorithm getSignatureAndHashAlgorithm() {
|
||
|
return this.signatureAndHashAlgorithm;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.tls.TlsCredentials
|
||
|
public Certificate getCertificate() {
|
||
|
return this.certificate;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.tls.TlsSignerCredentials
|
||
|
public byte[] generateCertificateSignature(byte[] bArr) throws IOException {
|
||
|
try {
|
||
|
return TlsUtils.isTLSv12(this.context) ? this.signer.generateRawSignature(this.signatureAndHashAlgorithm, this.privateKey, bArr) : this.signer.generateRawSignature(this.privateKey, bArr);
|
||
|
} catch (CryptoException e) {
|
||
|
throw new TlsFatalAlert((short) 80, e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public DefaultTlsSignerCredentials(TlsContext tlsContext, Certificate certificate, AsymmetricKeyParameter asymmetricKeyParameter, SignatureAndHashAlgorithm signatureAndHashAlgorithm) {
|
||
|
TlsSigner tlsECDSASigner;
|
||
|
if (certificate == null) {
|
||
|
throw new IllegalArgumentException("'certificate' cannot be null");
|
||
|
}
|
||
|
if (certificate.isEmpty()) {
|
||
|
throw new IllegalArgumentException("'certificate' cannot be empty");
|
||
|
}
|
||
|
if (asymmetricKeyParameter == null) {
|
||
|
throw new IllegalArgumentException("'privateKey' cannot be null");
|
||
|
}
|
||
|
if (!asymmetricKeyParameter.isPrivate()) {
|
||
|
throw new IllegalArgumentException("'privateKey' must be private");
|
||
|
}
|
||
|
if (TlsUtils.isTLSv12(tlsContext) && signatureAndHashAlgorithm == null) {
|
||
|
throw new IllegalArgumentException("'signatureAndHashAlgorithm' cannot be null for (D)TLS 1.2+");
|
||
|
}
|
||
|
if (asymmetricKeyParameter instanceof RSAKeyParameters) {
|
||
|
tlsECDSASigner = new TlsRSASigner();
|
||
|
} else if (asymmetricKeyParameter instanceof DSAPrivateKeyParameters) {
|
||
|
tlsECDSASigner = new TlsDSSSigner();
|
||
|
} else {
|
||
|
if (!(asymmetricKeyParameter instanceof ECPrivateKeyParameters)) {
|
||
|
StringBuilder sb = new StringBuilder("'privateKey' type not supported: ");
|
||
|
sb.append(asymmetricKeyParameter.getClass().getName());
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
tlsECDSASigner = new TlsECDSASigner();
|
||
|
}
|
||
|
this.signer = tlsECDSASigner;
|
||
|
tlsECDSASigner.init(tlsContext);
|
||
|
this.context = tlsContext;
|
||
|
this.certificate = certificate;
|
||
|
this.privateKey = asymmetricKeyParameter;
|
||
|
this.signatureAndHashAlgorithm = signatureAndHashAlgorithm;
|
||
|
}
|
||
|
|
||
|
public DefaultTlsSignerCredentials(TlsContext tlsContext, Certificate certificate, AsymmetricKeyParameter asymmetricKeyParameter) {
|
||
|
this(tlsContext, certificate, asymmetricKeyParameter, null);
|
||
|
}
|
||
|
}
|