Skip to content

Commit 920de25

Browse files
author
royb
committed
Added overwriteFriendlyName to PKCS12StoreParameter. default is on: preserves previous functionality. when set to false, allows user to save new store with modified friendlyNames or keep friendlyName as null.
1 parent 88c3a55 commit 920de25

23 files changed

+426
-17
lines changed

prov/src/main/java/org/bouncycastle/jcajce/PKCS12StoreParameter.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class PKCS12StoreParameter
1717
private final OutputStream out;
1818
private final ProtectionParameter protectionParameter;
1919
private final boolean forDEREncoding;
20+
private final boolean overwriteFriendlyName;
2021

2122
public PKCS12StoreParameter(OutputStream out, char[] password)
2223
{
@@ -25,19 +26,29 @@ public PKCS12StoreParameter(OutputStream out, char[] password)
2526

2627
public PKCS12StoreParameter(OutputStream out, ProtectionParameter protectionParameter)
2728
{
28-
this(out, protectionParameter, false);
29+
this(out, protectionParameter, false, true);
2930
}
3031

3132
public PKCS12StoreParameter(OutputStream out, char[] password, boolean forDEREncoding)
3233
{
33-
this(out, new KeyStore.PasswordProtection(password), forDEREncoding);
34+
this(out, new KeyStore.PasswordProtection(password), forDEREncoding, true);
3435
}
35-
3636
public PKCS12StoreParameter(OutputStream out, ProtectionParameter protectionParameter, boolean forDEREncoding)
37+
{
38+
this(out, protectionParameter, forDEREncoding, true);
39+
}
40+
41+
public PKCS12StoreParameter(OutputStream out, char[] password, boolean forDEREncoding, boolean overwriteFriendlyName)
42+
{
43+
this(out, new KeyStore.PasswordProtection(password), forDEREncoding, overwriteFriendlyName);
44+
}
45+
46+
public PKCS12StoreParameter(OutputStream out, ProtectionParameter protectionParameter, boolean forDEREncoding, boolean overwriteFriendlyName)
3747
{
3848
this.out = out;
3949
this.protectionParameter = protectionParameter;
4050
this.forDEREncoding = forDEREncoding;
51+
this.overwriteFriendlyName = overwriteFriendlyName;
4152
}
4253

4354
public OutputStream getOutputStream()
@@ -59,4 +70,15 @@ public boolean isForDEREncoding()
5970
{
6071
return forDEREncoding;
6172
}
73+
74+
/**
75+
* Return whether the KeyStore used with this parameter should overwrite friendlyName
76+
* when friendlyName is not present or does not equal the same name as alias
77+
*
78+
* @return true (default) to overwrite friendlyName, false otherwise,
79+
*/
80+
public boolean isOverwriteFriendlyName()
81+
{
82+
return overwriteFriendlyName;
83+
}
6284
}

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dh/BCDHPrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ public Enumeration getBagAttributeKeys()
243243
return attrCarrier.getBagAttributeKeys();
244244
}
245245

246+
public boolean hasFriendlyName()
247+
{
248+
return attrCarrier.hasFriendlyName();
249+
}
250+
251+
public void setFriendlyName(String friendlyName)
252+
{
253+
attrCarrier.setFriendlyName(friendlyName);
254+
}
255+
246256
private void readObject(
247257
ObjectInputStream in)
248258
throws IOException, ClassNotFoundException

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dsa/BCDSAPrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ public Enumeration getBagAttributeKeys()
145145
return attrCarrier.getBagAttributeKeys();
146146
}
147147

148+
public boolean hasFriendlyName()
149+
{
150+
return attrCarrier.hasFriendlyName();
151+
}
152+
153+
public void setFriendlyName(String friendlyName)
154+
{
155+
attrCarrier.setFriendlyName(friendlyName);
156+
}
157+
148158
private void readObject(
149159
ObjectInputStream in)
150160
throws IOException, ClassNotFoundException

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dstu/BCDSTU4145PrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ public Enumeration getBagAttributeKeys()
447447
return attrCarrier.getBagAttributeKeys();
448448
}
449449

450+
public boolean hasFriendlyName()
451+
{
452+
return attrCarrier.hasFriendlyName();
453+
}
454+
455+
public void setFriendlyName(String friendlyName)
456+
{
457+
attrCarrier.setFriendlyName(friendlyName);
458+
}
459+
450460
public void setPointFormat(String style)
451461
{
452462
withCompression = !("UNCOMPRESSED".equalsIgnoreCase(style));

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ public Enumeration getBagAttributeKeys()
385385
return attrCarrier.getBagAttributeKeys();
386386
}
387387

388+
public boolean hasFriendlyName()
389+
{
390+
return attrCarrier.hasFriendlyName();
391+
}
392+
393+
public void setFriendlyName(String friendlyName)
394+
{
395+
attrCarrier.setFriendlyName(friendlyName);
396+
}
397+
388398
public void setPointFormat(String style)
389399
{
390400
withCompression = !("UNCOMPRESSED".equalsIgnoreCase(style));

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,16 @@ public Enumeration getBagAttributeKeys()
459459
return attrCarrier.getBagAttributeKeys();
460460
}
461461

462+
public boolean hasFriendlyName()
463+
{
464+
return attrCarrier.hasFriendlyName();
465+
}
466+
467+
public void setFriendlyName(String friendlyName)
468+
{
469+
attrCarrier.setFriendlyName(friendlyName);
470+
}
471+
462472
public void setPointFormat(String style)
463473
{
464474
withCompression = !("UNCOMPRESSED".equalsIgnoreCase(style));

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ecgost12/BCECGOST3410_2012PrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ public Enumeration getBagAttributeKeys()
480480
return attrCarrier.getBagAttributeKeys();
481481
}
482482

483+
public boolean hasFriendlyName()
484+
{
485+
return attrCarrier.hasFriendlyName();
486+
}
487+
488+
public void setFriendlyName(String friendlyName)
489+
{
490+
attrCarrier.setFriendlyName(friendlyName);
491+
}
492+
483493
public void setPointFormat(String style)
484494
{
485495
withCompression = !("UNCOMPRESSED".equalsIgnoreCase(style));

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/elgamal/BCElGamalPrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,14 @@ public Enumeration getBagAttributeKeys()
194194
{
195195
return attrCarrier.getBagAttributeKeys();
196196
}
197+
198+
public boolean hasFriendlyName()
199+
{
200+
return attrCarrier.hasFriendlyName();
201+
}
202+
203+
public void setFriendlyName(String friendlyName)
204+
{
205+
attrCarrier.setFriendlyName(friendlyName);
206+
}
197207
}

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/gost/BCGOST3410PrivateKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ public Enumeration getBagAttributeKeys()
234234
return attrCarrier.getBagAttributeKeys();
235235
}
236236

237+
public boolean hasFriendlyName()
238+
{
239+
return attrCarrier.hasFriendlyName();
240+
}
241+
242+
public void setFriendlyName(String friendlyName)
243+
{
244+
attrCarrier.setFriendlyName(friendlyName);
245+
}
246+
237247
private void readObject(
238248
ObjectInputStream in)
239249
throws IOException, ClassNotFoundException

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/rsa/BCRSAPrivateKey.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ public Enumeration getBagAttributeKeys()
154154
return attrCarrier.getBagAttributeKeys();
155155
}
156156

157+
public boolean hasFriendlyName()
158+
{
159+
return attrCarrier.hasFriendlyName();
160+
}
161+
162+
public void setFriendlyName(String friendlyName)
163+
{
164+
attrCarrier.setFriendlyName(friendlyName);
165+
}
157166
private void readObject(
158167
ObjectInputStream in)
159168
throws IOException, ClassNotFoundException

0 commit comments

Comments
 (0)