Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8277224: sun.security.pkcs.PKCS9Attributes.toString() throws NPE #290

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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());