Skip to content

Commit eb6eefa

Browse files
committed
add vendor extension to nonce request and response
1 parent 812c16d commit eb6eefa

File tree

9 files changed

+106
-15
lines changed

9 files changed

+106
-15
lines changed

src/main/java/com/siemens/pki/cmpclientcomponent/configuration/ClientAttestationContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ default BigInteger getNonceRequestLen() {
5858
default String getNonceRequestType() {
5959
return null;
6060
}
61+
62+
/**
63+
* Siemens proprietary extension to carry additional data
64+
* @return additional data <code>null</code>
65+
*/
66+
default byte[] getNonceRequestVendorextension() {
67+
return null;
68+
}
6169
/**
6270
* get certs to include in {@link EvidenceBundle}
6371
* @return certs

src/main/java/com/siemens/pki/cmpclientcomponent/main/CmpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ public EnrollmentResult invokeEnrollment() {
425425
NonceRequest nonceRequest = new NonceRequest(
426426
attestationContext.getNonceRequestLen(),
427427
attestationContext.getNonceRequestType(),
428-
attestationContext.getNonceRequestHint());
428+
attestationContext.getNonceRequestHint(),
429+
attestationContext.getNonceRequestVendorextension());
429430
NonceRequestValue nonceRequestValue = new NonceRequestValue(new NonceRequest[] {nonceRequest});
430431
ratNonceResponse = requestHandler.sendReceiveInitialMessage(new PKIBody(
431432
PKIBody.TYPE_GEN_MSG,

src/main/java/com/siemens/pki/cmpracomponent/configuration/RatVerifierAdapter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ default String getHint() {
6565
default String getType() {
6666
return null;
6767
}
68+
69+
/**
70+
* Siemens proprietary extension to carry additional data
71+
* @return additional data or <code>null</code>
72+
*/
73+
default byte[] getVendorextension() {
74+
return null;
75+
}
6876
}
6977

7078
/**
@@ -73,9 +81,15 @@ default String getType() {
7381
* @param len the required length of the requested nonce, maybe <code>null</code>
7482
* @param type indicates which Evidence type to request a nonce for, OID as string or <code>null</code>
7583
* @param hint indicates which Verifier to request a nonce from, maybe <code>null</code>
84+
* @param vendorextension additional Siemens proprietary data, maybe <code>null</code>
7685
* @param encodedNonceRequest encoded NonceRequest containing len, type and hint
7786
* @return fresh BER encoded NonceResponse
7887
*/
7988
NonceResponseRet generateNonce(
80-
byte[] transactionId, BigInteger len, String type, String hint, byte[] encodedNonceRequest);
89+
byte[] transactionId,
90+
BigInteger len,
91+
String type,
92+
String hint,
93+
byte[] vendorextension,
94+
byte[] encodedNonceRequest);
8195
}

src/main/java/com/siemens/pki/cmpracomponent/msgprocessing/ServiceImplementation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.bouncycastle.asn1.ASN1EncodableVector;
5353
import org.bouncycastle.asn1.ASN1Integer;
5454
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
55+
import org.bouncycastle.asn1.ASN1OctetString;
5556
import org.bouncycastle.asn1.ASN1Primitive;
5657
import org.bouncycastle.asn1.ASN1Sequence;
5758
import org.bouncycastle.asn1.ASN1UTF8String;
@@ -313,8 +314,10 @@ private PKIBody handleGetFreshRatNonce(final PKIMessage msg, final InfoTypeAndVa
313314
ifNotNull(aktRequest.getLen(), ASN1Integer::getValue),
314315
ifNotNull(aktRequest.getType(), ASN1ObjectIdentifier::getId),
315316
ifNotNull(aktRequest.getHint(), ASN1UTF8String::getString),
317+
ifNotNull(aktRequest.getVendorextension(), ASN1OctetString::getOctets),
316318
aktRequest.getEncoded());
317-
responses[i] = new NonceResponse(ret.getNonce(), ret.getExpiry(), ret.getType(), ret.getHint());
319+
responses[i] = new NonceResponse(
320+
ret.getNonce(), ret.getExpiry(), ret.getType(), ret.getHint(), ret.getVendorextension());
318321
}
319322
persistencyContext.markAsPreparingGenm();
320323
return new PKIBody(

src/main/java/com/siemens/pki/verifieradapter/asn1/NonceRequestValue.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import org.bouncycastle.asn1.ASN1Integer;
2525
import org.bouncycastle.asn1.ASN1Object;
2626
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
27+
import org.bouncycastle.asn1.ASN1OctetString;
2728
import org.bouncycastle.asn1.ASN1Primitive;
2829
import org.bouncycastle.asn1.ASN1Sequence;
2930
import org.bouncycastle.asn1.ASN1UTF8String;
31+
import org.bouncycastle.asn1.DEROctetString;
3032
import org.bouncycastle.asn1.DERSequence;
3133
import org.bouncycastle.asn1.DERUTF8String;
3234

@@ -42,6 +44,8 @@
4244
* -- indicates which Evidence type to request a nonce for
4345
* hint UTF8String OPTIONAL
4446
* -- indicates which Verifier to request a nonce from
47+
* vendorextension OCTET STRING OPTIONAL
48+
* -- Siemens proprietary extension to carry additional data
4549
* }
4650
* }
4751
*/
@@ -62,23 +66,32 @@ public ASN1UTF8String getHint() {
6266
return hint;
6367
}
6468

69+
public ASN1OctetString getVendorextension() {
70+
return vendorextension;
71+
}
72+
6573
private ASN1Integer len = null;
6674
private ASN1ObjectIdentifier type = null;
6775
private ASN1UTF8String hint = null;
76+
private ASN1OctetString vendorextension = null;
6877

69-
public NonceRequest(ASN1Integer len, ASN1ObjectIdentifier type, ASN1UTF8String hint) {
78+
public NonceRequest(
79+
ASN1Integer len, ASN1ObjectIdentifier type, ASN1UTF8String hint, ASN1OctetString vendorextension) {
7080
this.len = len;
7181
this.type = type;
7282
this.hint = hint;
83+
this.vendorextension = vendorextension;
7384
}
7485

7586
public ASN1Primitive toASN1Primitive() {
7687

77-
ASN1EncodableVector v = new ASN1EncodableVector(3);
88+
ASN1EncodableVector v = new ASN1EncodableVector(4);
7889

7990
addOptional(v, len);
8091
addOptional(v, type);
8192
addOptional(v, hint);
93+
addOptional(v, vendorextension);
94+
8295
return new DERSequence(v);
8396
}
8497

@@ -112,16 +125,28 @@ private NonceRequest(ASN1Sequence seq) {
112125
}
113126
next = en.nextElement();
114127
}
115-
if (next != null) {
128+
if (next instanceof ASN1UTF8String) {
116129
hint = ASN1UTF8String.getInstance(next);
130+
if (!en.hasMoreElements()) {
131+
return;
132+
}
133+
next = en.nextElement();
134+
}
135+
if (next instanceof ASN1OctetString) {
136+
vendorextension = ASN1OctetString.getInstance(next);
117137
}
118138
}
119139

120-
public NonceRequest(BigInteger nonceRequestLen, String nonceRequestType, String nonceRequestHint) {
140+
public NonceRequest(
141+
BigInteger nonceRequestLen,
142+
String nonceRequestType,
143+
String nonceRequestHint,
144+
byte[] nonceRequestVendorextension) {
121145
this(
122146
nonceRequestLen != null ? new ASN1Integer(nonceRequestLen) : null,
123147
nonceRequestType != null ? new ASN1ObjectIdentifier(nonceRequestType) : null,
124-
nonceRequestHint != null ? new DERUTF8String(nonceRequestHint) : null);
148+
nonceRequestHint != null ? new DERUTF8String(nonceRequestHint) : null,
149+
nonceRequestVendorextension != null ? new DEROctetString(nonceRequestVendorextension) : null);
125150
}
126151

127152
private void addOptional(ASN1EncodableVector v, ASN1Encodable obj) {

src/main/java/com/siemens/pki/verifieradapter/asn1/NonceResponseValue.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
* -- indicates which Evidence type to request a nonce for
4848
* hint UTF8String OPTIONAL
4949
* -- indicates which Verifier to request a nonce from
50+
* vendorextension OCTET STRING OPTIONAL
51+
* -- Siemens proprietary extension to carry additional data
5052
* }
5153
* }
5254
*/
@@ -60,6 +62,7 @@ public static class NonceResponse extends ASN1Object {
6062
private ASN1Integer expiry = null;
6163
private ASN1ObjectIdentifier type = null;
6264
private ASN1UTF8String hint = null;
65+
private ASN1OctetString vendorextension = null;
6366

6467
public ASN1Primitive toASN1Primitive() {
6568

@@ -69,6 +72,8 @@ public ASN1Primitive toASN1Primitive() {
6972
addOptional(v, expiry);
7073
addOptional(v, type);
7174
addOptional(v, hint);
75+
addOptional(v, vendorextension);
76+
7277
return new DERSequence(v);
7378
}
7479

@@ -107,23 +112,38 @@ private NonceResponse(ASN1Sequence seq) {
107112
}
108113
next = en.nextElement();
109114
}
110-
hint = ASN1UTF8String.getInstance(next);
115+
if (next instanceof ASN1UTF8String) {
116+
hint = ASN1UTF8String.getInstance(next);
117+
if (!en.hasMoreElements()) {
118+
return;
119+
}
120+
next = en.nextElement();
121+
}
122+
if (next instanceof ASN1OctetString) {
123+
vendorextension = ASN1OctetString.getInstance(next);
124+
}
111125
}
112126

113127
public NonceResponse(
114-
ASN1OctetString nonce, ASN1Integer expiry, ASN1ObjectIdentifier type, ASN1UTF8String hint) {
128+
ASN1OctetString nonce,
129+
ASN1Integer expiry,
130+
ASN1ObjectIdentifier type,
131+
ASN1UTF8String hint,
132+
ASN1OctetString vendorextension) {
115133
this.nonce = nonce;
116134
this.expiry = expiry;
117135
this.type = type;
118136
this.hint = hint;
137+
this.vendorextension = vendorextension;
119138
}
120139

121-
public NonceResponse(byte[] nonce, Integer expiry, String type, String hint) {
140+
public NonceResponse(byte[] nonce, Integer expiry, String type, String hint, byte[] vendorextension) {
122141
this(
123142
nonce != null ? new DEROctetString(nonce) : null,
124143
expiry != null ? new ASN1Integer(expiry) : null,
125144
type != null ? new ASN1ObjectIdentifier(type) : null,
126-
hint != null ? new DERUTF8String(hint) : null);
145+
hint != null ? new DERUTF8String(hint) : null,
146+
vendorextension != null ? new DEROctetString(vendorextension) : null);
127147
}
128148

129149
public ASN1OctetString getNonce() {
@@ -142,6 +162,10 @@ public ASN1UTF8String getHint() {
142162
return hint;
143163
}
144164

165+
public ASN1OctetString getVendorextension() {
166+
return vendorextension;
167+
}
168+
145169
private void addOptional(ASN1EncodableVector v, ASN1Encodable obj) {
146170
if (obj != null) {
147171
v.add(obj);

src/test/java/com/siemens/pki/cmpclientcomponent/test/TestCrWithRAT.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public NonceResponseRet generateNonce(
224224
BigInteger len,
225225
String type,
226226
String hint,
227+
byte[] vendorextension,
227228
byte[] encodedNonceRequest) {
228229
LOGGER.debug(
229230
"generateNonce called with certprofile: {}, type: {}",
@@ -246,6 +247,11 @@ public String getHint() {
246247
return "responded hint: " + hint;
247248
}
248249

250+
@Override
251+
public byte[] getVendorextension() {
252+
return vendorextension;
253+
}
254+
249255
@Override
250256
public String getType() {
251257
return new ASN1ObjectIdentifier("1.7.8.9").getId();
@@ -432,6 +438,11 @@ public BigInteger getNonceRequestLen() {
432438
return new BigInteger("16");
433439
}
434440

441+
@Override
442+
public byte[] getNonceRequestVendorextension() {
443+
return "vendor extension".getBytes();
444+
}
445+
435446
@Override
436447
public Certificate[] getEvidenceBundleCerts() {
437448
// just provide some certificates
@@ -457,6 +468,8 @@ public byte[] getEvidenceStatement(byte[] attestationNonce) {
457468
NonceResponse nonceResponse = NonceResponse.getInstance(attestationNonce);
458469
assertNotNull(nonceResponse.getExpiry());
459470
assertNotNull(nonceResponse.getHint());
471+
assertNotNull(nonceResponse.getVendorextension());
472+
460473
try {
461474
return new EvidenceStatement(
462475
nonceResponse.getType().branch("88"),

src/test/java/com/siemens/pki/verifieradapter/asn1/TestRatAsn1.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,22 @@ public void testEvidenceBundle() throws IOException {
6767

6868
@Test
6969
public void testNonceRequestValue() throws IOException {
70-
byte[] encoded = new NonceRequestValue(new NonceRequest[] {new NonceRequest((BigInteger) null, null, null)})
70+
byte[] encoded = new NonceRequestValue(
71+
new NonceRequest[] {new NonceRequest((BigInteger) null, null, null, null)})
7172
.getEncoded();
7273
NonceRequestValue decoded = NonceRequestValue.getInstance(encoded);
7374
assertEquals(1, decoded.getNonceRequests().length);
7475
final NonceRequest nonceRequest = decoded.getNonceRequests()[0];
7576
assertNull(nonceRequest.getLen());
7677
assertNull(nonceRequest.getType());
7778
assertNull(nonceRequest.getHint());
79+
assertNull(nonceRequest.getVendorextension());
7880
}
7981

8082
@Test
8183
public void testNonceResponseValue() throws IOException {
82-
byte[] encoded = new NonceResponseValue(new NonceResponse[] {new NonceResponse(new byte[10], null, null, null)})
84+
byte[] encoded = new NonceResponseValue(
85+
new NonceResponse[] {new NonceResponse(new byte[10], null, null, null, null)})
8386
.getEncoded();
8487
NonceResponseValue decoded = NonceResponseValue.getInstance(encoded);
8588
assertEquals(1, decoded.getNonceResponse().length);
@@ -88,5 +91,6 @@ public void testNonceResponseValue() throws IOException {
8891
assertNull(nonceRequest.getExpiry());
8992
assertNull(nonceRequest.getType());
9093
assertNull(nonceRequest.getHint());
94+
assertNull(nonceRequest.getVendorextension());
9195
}
9296
}

src/test/java/com/siemens/pki/verifieradapter/asn1/package-info.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)