Skip to content
Permalink
Browse files
8277224: sun.security.pkcs.PKCS9Attributes.toString() throws NPE
Backport-of: 6bb04626af6574ef1e8d4b7dad0389d4b59f5d08
  • Loading branch information
Yuri Nesterenko committed Dec 21, 2021
1 parent 9beff4a commit c53498b131d2020fea93e065f809645269eb9a22
Showing with 14 additions and 5 deletions.
  1. +7 −3 src/java.base/share/classes/sun/security/pkcs/PKCS9Attributes.java
  2. +7 −2 test/jdk/sun/security/x509/AlgorithmId/NonStandardNames.java
@@ -277,11 +277,13 @@ public PKCS9Attribute getAttribute(String name) {
*/
public PKCS9Attribute[] getAttributes() {
PKCS9Attribute[] attribs = new PKCS9Attribute[attributes.size()];
ObjectIdentifier oid;

int j = 0;
for (int i=1; i < PKCS9Attribute.PKCS9_OIDS.length &&
j < attribs.length; i++) {
if (PKCS9Attribute.PKCS9_OIDS[i] == null) {
continue;
}
attribs[j] = getAttribute(PKCS9Attribute.PKCS9_OIDS[i]);

if (attribs[j] != null)
@@ -325,11 +327,13 @@ public String toString() {
StringBuilder sb = new StringBuilder(200);
sb.append("PKCS9 Attributes: [\n\t");

ObjectIdentifier oid;
PKCS9Attribute value;

boolean first = true;
for (int i = 1; i < PKCS9Attribute.PKCS9_OIDS.length; i++) {
if (PKCS9Attribute.PKCS9_OIDS[i] == null) {
continue;
}
value = getAttribute(PKCS9Attribute.PKCS9_OIDS[i]);

if (value == null) continue;
@@ -340,7 +344,7 @@ public String toString() {
else
sb.append(";\n\t");

sb.append(value.toString());
sb.append(value);
}

sb.append("\n\t] (end PKCS9 Attributes)");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@

/*
* @test
* @bug 7180907
* @bug 7180907 8277224
* @summary Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
* @modules java.base/sun.security.pkcs
* java.base/sun.security.tools.keytool
@@ -60,8 +60,13 @@ public static void main(String[] args) throws Exception {
PKCS9Attributes authed = new PKCS9Attributes(new PKCS9Attribute[]{
new PKCS9Attribute(PKCS9Attribute.CONTENT_TYPE_OID, ContentInfo.DATA_OID),
new PKCS9Attribute(PKCS9Attribute.MESSAGE_DIGEST_OID, md.digest(data)),
new PKCS9Attribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID, "test".getBytes())
});

// test PKCS9Attributes.toString(), PKCS9Attributes.getAttributes()
System.out.println(authed);
authed.getAttributes();

Signature s = Signature.getInstance("SHA256withRSA");
s.initSign(cakg.getPrivateKey());
s.update(authed.getDerEncoding());

1 comment on commit c53498b

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on c53498b Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.