Skip to content

Commit

Permalink
8321925: sun/security/mscapi/KeytoolChangeAlias.java fails with "Alia…
Browse files Browse the repository at this point in the history
…s <246810> does not exist"

Reviewed-by: rhalade
  • Loading branch information
Matthew Donovan committed Jan 18, 2024
1 parent bfd2afe commit b6233c3
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions test/jdk/sun/security/mscapi/KeytoolChangeAlias.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, 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
Expand All @@ -25,6 +25,7 @@
import jdk.test.lib.security.CertUtils;

import java.security.KeyStore;
import java.security.SecureRandom;

/*
* @test
Expand All @@ -35,15 +36,17 @@
*/
public class KeytoolChangeAlias {
public static void main(String[] args) throws Exception {

SecureRandom random = new SecureRandom();
String alias = Integer.toString(random.nextInt(1000, 8192));
String newAlias = alias + "1";
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);

try {
ks.setCertificateEntry("246810", CertUtils.getCertFromFile("246810.cer"));
ks.setCertificateEntry(alias, CertUtils.getCertFromFile("246810.cer"));

if (ks.containsAlias("13579")) {
ks.deleteEntry("13579");
if (ks.containsAlias(newAlias)) {
ks.deleteEntry(newAlias);
}

int before = ks.size();
Expand All @@ -52,8 +55,8 @@ public static void main(String[] args) throws Exception {

SecurityTools.keytool("-changealias",
"-storetype", "Windows-My",
"-alias", "246810",
"-destalias", "13579").shouldHaveExitValue(0);
"-alias", alias,
"-destalias", newAlias).shouldHaveExitValue(0);

ks.load(null, null);

Expand All @@ -63,13 +66,23 @@ public static void main(String[] args) throws Exception {
+ ". After: " + ks.size());
}

if (!ks.containsAlias("13579")) {
if (!ks.containsAlias(newAlias)) {
throw new Exception("error: cannot find the new alias name"
+ " in the Windows-MY store");
}
} finally {
ks.deleteEntry("13579");
ks.deleteEntry("246810");
try {
ks.deleteEntry(newAlias);
} catch (Exception e) {
System.err.println("Couldn't delete alias " + newAlias);
e.printStackTrace(System.err);
}
try {
ks.deleteEntry(alias);
} catch (Exception e) {
System.err.println("Couldn't delete alias " + alias);
e.printStackTrace(System.err);
}
ks.store(null, null);
}
}
Expand Down

5 comments on commit b6233c3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@sendaoYan
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on b6233c3 Mar 28, 2024

Choose a reason for hiding this comment

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

@sendaoYan the backport was successfully created on the branch backport-sendaoYan-b6233c3d in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-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 b6233c3d from the openjdk/jdk repository.

The commit being backported was authored by Matthew Donovan on 18 Jan 2024 and was reviewed by Rajan Halade.

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/jdk21u-dev:

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

@sendaoYan
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on b6233c3 Mar 28, 2024

Choose a reason for hiding this comment

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

@sendaoYan the backport was successfully created on the branch backport-sendaoYan-b6233c3d in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-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 b6233c3d from the openjdk/jdk repository.

The commit being backported was authored by Matthew Donovan on 18 Jan 2024 and was reviewed by Rajan Halade.

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/jdk17u-dev:

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

Please sign in to comment.