author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 25859 | jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMX509IssuerSerial.java@3317bb8137f4 |
child 50614 | 3810c9a2efa1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1337 | 2 |
* reserved comment block |
3 |
* DO NOT REMOVE OR ALTER! |
|
2 | 4 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
7 |
* or more contributor license agreements. See the NOTICE file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
9 |
* regarding copyright ownership. The ASF licenses this file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
10 |
* to you under the Apache License, Version 2.0 (the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
11 |
* "License"); you may not use this file except in compliance |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
1337 | 13 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
1337 | 15 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
16 |
* Unless required by applicable law or agreed to in writing, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
17 |
* software distributed under the License is distributed on an |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
19 |
* KIND, either express or implied. See the License for the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
21 |
* under the License. |
1337 | 22 |
*/ |
23 |
/* |
|
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
19051
diff
changeset
|
24 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
1337 | 25 |
*/ |
26 |
/* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
27 |
* $Id: DOMX509IssuerSerial.java 1333415 2012-05-03 12:03:51Z coheigea $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import javax.xml.crypto.*; |
|
32 |
import javax.xml.crypto.dom.DOMCryptoContext; |
|
33 |
import javax.xml.crypto.dsig.*; |
|
34 |
import javax.xml.crypto.dsig.keyinfo.X509IssuerSerial; |
|
35 |
||
36 |
import java.math.BigInteger; |
|
37 |
import javax.security.auth.x500.X500Principal; |
|
38 |
import org.w3c.dom.Document; |
|
39 |
import org.w3c.dom.Element; |
|
40 |
import org.w3c.dom.Node; |
|
41 |
||
42 |
/** |
|
43 |
* DOM-based implementation of X509IssuerSerial. |
|
44 |
* |
|
45 |
* @author Sean Mullan |
|
46 |
*/ |
|
47 |
public final class DOMX509IssuerSerial extends DOMStructure |
|
48 |
implements X509IssuerSerial { |
|
49 |
||
50 |
private final String issuerName; |
|
51 |
private final BigInteger serialNumber; |
|
52 |
||
53 |
/** |
|
54 |
* Creates a <code>DOMX509IssuerSerial</code> containing the specified |
|
55 |
* issuer distinguished name/serial number pair. |
|
56 |
* |
|
57 |
* @param issuerName the X.509 issuer distinguished name in RFC 2253 |
|
58 |
* String format |
|
59 |
* @param serialNumber the serial number |
|
60 |
* @throws IllegalArgumentException if the format of <code>issuerName</code> |
|
61 |
* is not RFC 2253 compliant |
|
62 |
* @throws NullPointerException if <code>issuerName</code> or |
|
63 |
* <code>serialNumber</code> is <code>null</code> |
|
64 |
*/ |
|
65 |
public DOMX509IssuerSerial(String issuerName, BigInteger serialNumber) { |
|
66 |
if (issuerName == null) { |
|
67 |
throw new NullPointerException("issuerName cannot be null"); |
|
68 |
} |
|
69 |
if (serialNumber == null) { |
|
70 |
throw new NullPointerException("serialNumber cannot be null"); |
|
71 |
} |
|
72 |
// check that issuer distinguished name conforms to RFC 2253 |
|
73 |
new X500Principal(issuerName); |
|
74 |
this.issuerName = issuerName; |
|
75 |
this.serialNumber = serialNumber; |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Creates a <code>DOMX509IssuerSerial</code> from an element. |
|
80 |
* |
|
81 |
* @param isElem an X509IssuerSerial element |
|
82 |
*/ |
|
19051
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
83 |
public DOMX509IssuerSerial(Element isElem) throws MarshalException { |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
84 |
Element iNElem = DOMUtils.getFirstChildElement(isElem, |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
85 |
"X509IssuerName"); |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
86 |
Element sNElem = DOMUtils.getNextSiblingElement(iNElem, |
6c0cfc00b3ed
8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents:
18780
diff
changeset
|
87 |
"X509SerialNumber"); |
2 | 88 |
issuerName = iNElem.getFirstChild().getNodeValue(); |
89 |
serialNumber = new BigInteger(sNElem.getFirstChild().getNodeValue()); |
|
90 |
} |
|
91 |
||
92 |
public String getIssuerName() { |
|
93 |
return issuerName; |
|
94 |
} |
|
95 |
||
96 |
public BigInteger getSerialNumber() { |
|
97 |
return serialNumber; |
|
98 |
} |
|
99 |
||
100 |
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
101 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
102 |
{ |
2 | 103 |
Document ownerDoc = DOMUtils.getOwnerDocument(parent); |
104 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
105 |
Element isElem = DOMUtils.createElement(ownerDoc, "X509IssuerSerial", |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
106 |
XMLSignature.XMLNS, dsPrefix); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
107 |
Element inElem = DOMUtils.createElement(ownerDoc, "X509IssuerName", |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
108 |
XMLSignature.XMLNS, dsPrefix); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
109 |
Element snElem = DOMUtils.createElement(ownerDoc, "X509SerialNumber", |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
110 |
XMLSignature.XMLNS, dsPrefix); |
2 | 111 |
inElem.appendChild(ownerDoc.createTextNode(issuerName)); |
112 |
snElem.appendChild(ownerDoc.createTextNode(serialNumber.toString())); |
|
113 |
isElem.appendChild(inElem); |
|
114 |
isElem.appendChild(snElem); |
|
115 |
parent.appendChild(isElem); |
|
116 |
} |
|
117 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
118 |
@Override |
2 | 119 |
public boolean equals(Object obj) { |
120 |
if (this == obj) { |
|
121 |
return true; |
|
122 |
} |
|
123 |
if (!(obj instanceof X509IssuerSerial)) { |
|
124 |
return false; |
|
125 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
126 |
X509IssuerSerial ois = (X509IssuerSerial)obj; |
2 | 127 |
return (issuerName.equals(ois.getIssuerName()) && |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
128 |
serialNumber.equals(ois.getSerialNumber())); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
129 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
130 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
131 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
132 |
public int hashCode() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
133 |
int result = 17; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
134 |
result = 31 * result + issuerName.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
135 |
result = 31 * result + serialNumber.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
136 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
5506
diff
changeset
|
137 |
return result; |
2 | 138 |
} |
139 |
} |