Skip to content
Permalink
Browse files
8277224: sun.security.pkcs.PKCS9Attributes.toString() throws NPE
Reviewed-by: weijun
  • Loading branch information
coffeys committed Nov 17, 2021
1 parent d8c0280 commit 6bb04626af6574ef1e8d4b7dad0389d4b59f5d08
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
@@ -275,11 +275,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)
@@ -323,11 +325,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;
@@ -338,7 +342,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());

3 comments on commit 6bb0462

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 6bb0462 Nov 17, 2021

Choose a reason for hiding this comment

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

@TheRealMDoerr
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr commented on 6bb0462 Nov 23, 2021

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 6bb0462 Nov 23, 2021

Choose a reason for hiding this comment

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

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-6bb04626 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6bb04626 from the openjdk/jdk repository.

The commit being backported was authored by Sean Coffey on 17 Nov 2021 and was reviewed by Weijun Wang.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-6bb04626:TheRealMDoerr-backport-6bb04626
$ git checkout TheRealMDoerr-backport-6bb04626
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-6bb04626

Please sign in to comment.