blob: 07659593c61e5d482ee71b6ceb0042c0de2c1296 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.spongycastle.cert.crmf;
import org.spongycastle.asn1.DERBitString;
import org.spongycastle.asn1.crmf.CertRequest;
import org.spongycastle.asn1.crmf.PKMACValue;
import org.spongycastle.asn1.crmf.POPOSigningKey;
import org.spongycastle.asn1.crmf.POPOSigningKeyInput;
import org.spongycastle.asn1.x509.GeneralName;
import org.spongycastle.asn1.x509.SubjectPublicKeyInfo;
import org.spongycastle.operator.ContentSigner;
public class ProofOfPossessionSigningKeyBuilder
{
private CertRequest certRequest;
private SubjectPublicKeyInfo pubKeyInfo;
private GeneralName name;
private PKMACValue publicKeyMAC;
public ProofOfPossessionSigningKeyBuilder(CertRequest certRequest)
{
this.certRequest = certRequest;
}
public ProofOfPossessionSigningKeyBuilder(SubjectPublicKeyInfo pubKeyInfo)
{
this.pubKeyInfo = pubKeyInfo;
}
public ProofOfPossessionSigningKeyBuilder setSender(GeneralName name)
{
this.name = name;
return this;
}
public ProofOfPossessionSigningKeyBuilder setPublicKeyMac(PKMACValueGenerator generator, char[] password)
throws CRMFException
{
this.publicKeyMAC = generator.generate(password, pubKeyInfo);
return this;
}
public POPOSigningKey build(ContentSigner signer)
{
if (name != null && publicKeyMAC != null)
{
throw new IllegalStateException("name and publicKeyMAC cannot both be set.");
}
POPOSigningKeyInput popo;
if (certRequest != null)
{
popo = null;
CRMFUtil.derEncodeToStream(certRequest, signer.getOutputStream());
}
else if (name != null)
{
popo = new POPOSigningKeyInput(name, pubKeyInfo);
CRMFUtil.derEncodeToStream(popo, signer.getOutputStream());
}
else
{
popo = new POPOSigningKeyInput(publicKeyMAC, pubKeyInfo);
CRMFUtil.derEncodeToStream(popo, signer.getOutputStream());
}
return new POPOSigningKey(popo, signer.getAlgorithmIdentifier(), new DERBitString(signer.getSignature()));
}
}
|