2
|
1 |
/*
|
1337
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
2
|
4 |
*/
|
|
5 |
/*
|
1337
|
6 |
* Copyright 2005 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
/*
|
|
22 |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
|
|
23 |
*/
|
|
24 |
/*
|
|
25 |
* $Id: DOMX509IssuerSerial.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
|
2
|
26 |
*/
|
|
27 |
package org.jcp.xml.dsig.internal.dom;
|
|
28 |
|
|
29 |
import javax.xml.crypto.*;
|
|
30 |
import javax.xml.crypto.dom.DOMCryptoContext;
|
|
31 |
import javax.xml.crypto.dsig.*;
|
|
32 |
import javax.xml.crypto.dsig.keyinfo.X509IssuerSerial;
|
|
33 |
|
|
34 |
import java.math.BigInteger;
|
|
35 |
import javax.security.auth.x500.X500Principal;
|
|
36 |
import org.w3c.dom.Document;
|
|
37 |
import org.w3c.dom.Element;
|
|
38 |
import org.w3c.dom.Node;
|
|
39 |
|
|
40 |
/**
|
|
41 |
* DOM-based implementation of X509IssuerSerial.
|
|
42 |
*
|
|
43 |
* @author Sean Mullan
|
|
44 |
*/
|
|
45 |
public final class DOMX509IssuerSerial extends DOMStructure
|
|
46 |
implements X509IssuerSerial {
|
|
47 |
|
|
48 |
private final String issuerName;
|
|
49 |
private final BigInteger serialNumber;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Creates a <code>DOMX509IssuerSerial</code> containing the specified
|
|
53 |
* issuer distinguished name/serial number pair.
|
|
54 |
*
|
|
55 |
* @param issuerName the X.509 issuer distinguished name in RFC 2253
|
|
56 |
* String format
|
|
57 |
* @param serialNumber the serial number
|
|
58 |
* @throws IllegalArgumentException if the format of <code>issuerName</code>
|
|
59 |
* is not RFC 2253 compliant
|
|
60 |
* @throws NullPointerException if <code>issuerName</code> or
|
|
61 |
* <code>serialNumber</code> is <code>null</code>
|
|
62 |
*/
|
|
63 |
public DOMX509IssuerSerial(String issuerName, BigInteger serialNumber) {
|
|
64 |
if (issuerName == null) {
|
|
65 |
throw new NullPointerException("issuerName cannot be null");
|
|
66 |
}
|
|
67 |
if (serialNumber == null) {
|
|
68 |
throw new NullPointerException("serialNumber cannot be null");
|
|
69 |
}
|
|
70 |
// check that issuer distinguished name conforms to RFC 2253
|
|
71 |
new X500Principal(issuerName);
|
|
72 |
this.issuerName = issuerName;
|
|
73 |
this.serialNumber = serialNumber;
|
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Creates a <code>DOMX509IssuerSerial</code> from an element.
|
|
78 |
*
|
|
79 |
* @param isElem an X509IssuerSerial element
|
|
80 |
*/
|
|
81 |
public DOMX509IssuerSerial(Element isElem) {
|
|
82 |
Element iNElem = DOMUtils.getFirstChildElement(isElem);
|
|
83 |
Element sNElem = DOMUtils.getNextSiblingElement(iNElem);
|
|
84 |
issuerName = iNElem.getFirstChild().getNodeValue();
|
|
85 |
serialNumber = new BigInteger(sNElem.getFirstChild().getNodeValue());
|
|
86 |
}
|
|
87 |
|
|
88 |
public String getIssuerName() {
|
|
89 |
return issuerName;
|
|
90 |
}
|
|
91 |
|
|
92 |
public BigInteger getSerialNumber() {
|
|
93 |
return serialNumber;
|
|
94 |
}
|
|
95 |
|
|
96 |
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
|
|
97 |
throws MarshalException {
|
|
98 |
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
|
|
99 |
|
|
100 |
Element isElem = DOMUtils.createElement
|
|
101 |
(ownerDoc, "X509IssuerSerial", XMLSignature.XMLNS, dsPrefix);
|
|
102 |
Element inElem = DOMUtils.createElement
|
|
103 |
(ownerDoc, "X509IssuerName", XMLSignature.XMLNS, dsPrefix);
|
|
104 |
Element snElem = DOMUtils.createElement
|
|
105 |
(ownerDoc, "X509SerialNumber", XMLSignature.XMLNS, dsPrefix);
|
|
106 |
inElem.appendChild(ownerDoc.createTextNode(issuerName));
|
|
107 |
snElem.appendChild(ownerDoc.createTextNode(serialNumber.toString()));
|
|
108 |
isElem.appendChild(inElem);
|
|
109 |
isElem.appendChild(snElem);
|
|
110 |
parent.appendChild(isElem);
|
|
111 |
}
|
|
112 |
|
|
113 |
public boolean equals(Object obj) {
|
|
114 |
if (this == obj) {
|
|
115 |
return true;
|
|
116 |
}
|
|
117 |
if (!(obj instanceof X509IssuerSerial)) {
|
|
118 |
return false;
|
|
119 |
}
|
|
120 |
X509IssuerSerial ois = (X509IssuerSerial) obj;
|
|
121 |
return (issuerName.equals(ois.getIssuerName()) &&
|
|
122 |
serialNumber.equals(ois.getSerialNumber()));
|
|
123 |
}
|
|
124 |
}
|