@@ -1812,6 +1812,16 @@ else if (target instanceof OpenPGPUserAttribute)
1812
1812
}
1813
1813
}
1814
1814
1815
+ /**
1816
+ * Verify a signature of type {@link PGPSignature#PRIMARYKEY_BINDING}, which is typically embedded as
1817
+ * {@link org.bouncycastle.bcpg.sig.EmbeddedSignature} inside a signature of type
1818
+ * {@link PGPSignature#SUBKEY_BINDING} for a signing capable subkey.
1819
+ *
1820
+ * @param contentVerifierBuilderProvider provider for content verifier builders
1821
+ * @param policy algorithm policy
1822
+ * @param signatureCreationTime creation time of the signature
1823
+ * @throws PGPSignatureException if an exception happens during signature verification
1824
+ */
1815
1825
private void verifyEmbeddedPrimaryKeyBinding (PGPContentVerifierBuilderProvider contentVerifierBuilderProvider ,
1816
1826
OpenPGPPolicy policy , Date signatureCreationTime )
1817
1827
throws PGPSignatureException
@@ -1893,6 +1903,15 @@ private void verifyEmbeddedPrimaryKeyBinding(PGPContentVerifierBuilderProvider c
1893
1903
throw exception ;
1894
1904
}
1895
1905
1906
+ /**
1907
+ * Verify a signature of type {@link PGPSignature#DIRECT_KEY}, {@link PGPSignature#KEY_REVOCATION},
1908
+ * {@link PGPSignature#SUBKEY_BINDING} or {@link PGPSignature#SUBKEY_REVOCATION}.
1909
+ *
1910
+ * @param issuer issuing component key
1911
+ * @param target targeted component key
1912
+ * @param contentVerifierBuilderProvider provider for content verifier builders
1913
+ * @throws PGPSignatureException if an exception happens during signature verification
1914
+ */
1896
1915
protected void verifyKeySignature (
1897
1916
OpenPGPComponentKey issuer ,
1898
1917
OpenPGPComponentKey target ,
@@ -1931,6 +1950,17 @@ else if (signature.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING)
1931
1950
}
1932
1951
}
1933
1952
1953
+ /**
1954
+ * Verify a certification signature over an {@link OpenPGPUserId}.
1955
+ * The signature is of type {@link PGPSignature#DEFAULT_CERTIFICATION}, {@link PGPSignature#NO_CERTIFICATION},
1956
+ * {@link PGPSignature#CASUAL_CERTIFICATION}, {@link PGPSignature#POSITIVE_CERTIFICATION} or
1957
+ * {@link PGPSignature#CERTIFICATION_REVOCATION}.
1958
+ *
1959
+ * @param issuer issuing component key
1960
+ * @param target targeted userid
1961
+ * @param contentVerifierBuilderProvider provider for content verifier builders
1962
+ * @throws PGPSignatureException if an exception happens during signature verification
1963
+ */
1934
1964
protected void verifyUserIdSignature (OpenPGPComponentKey issuer ,
1935
1965
OpenPGPUserId target ,
1936
1966
PGPContentVerifierBuilderProvider contentVerifierBuilderProvider )
@@ -1953,6 +1983,17 @@ protected void verifyUserIdSignature(OpenPGPComponentKey issuer,
1953
1983
}
1954
1984
}
1955
1985
1986
+ /**
1987
+ * Verify a certification signature over an {@link OpenPGPUserAttribute}.
1988
+ * The signature is of type {@link PGPSignature#DEFAULT_CERTIFICATION}, {@link PGPSignature#NO_CERTIFICATION},
1989
+ * {@link PGPSignature#CASUAL_CERTIFICATION}, {@link PGPSignature#POSITIVE_CERTIFICATION} or
1990
+ * {@link PGPSignature#CERTIFICATION_REVOCATION}.
1991
+ *
1992
+ * @param issuer issuing component key
1993
+ * @param target targeted userid
1994
+ * @param contentVerifierBuilderProvider provider for content verifier builders
1995
+ * @throws PGPSignatureException if an exception happens during signature verification
1996
+ */
1956
1997
protected void verifyUserAttributeSignature (OpenPGPComponentKey issuer ,
1957
1998
OpenPGPUserAttribute target ,
1958
1999
PGPContentVerifierBuilderProvider contentVerifierBuilderProvider )
@@ -2823,13 +2864,20 @@ private OpenPGPSignatureChain(OpenPGPSignatureChain copy)
2823
2864
this (copy .chainLinks );
2824
2865
}
2825
2866
2867
+ /**
2868
+ * Return the signature from the leaf of the chain, which directly applies to the
2869
+ * {@link OpenPGPCertificateComponent}.
2870
+ *
2871
+ * @return signature
2872
+ */
2826
2873
public OpenPGPComponentSignature getSignature ()
2827
2874
{
2828
2875
return getLeafLink ().getSignature ();
2829
2876
}
2830
2877
2831
2878
/**
2832
2879
* Return an NEW instance of the {@link OpenPGPSignatureChain} with the new link appended.
2880
+ *
2833
2881
* @param sig signature
2834
2882
* @return new instance
2835
2883
*/
@@ -2847,31 +2895,65 @@ public OpenPGPSignatureChain plus(OpenPGPComponentSignature sig)
2847
2895
return chain ;
2848
2896
}
2849
2897
2898
+ /**
2899
+ * Factory method for creating an {@link OpenPGPSignatureChain} with only a single link.
2900
+ *
2901
+ * @param sig signature
2902
+ * @return chain
2903
+ */
2850
2904
public static OpenPGPSignatureChain direct (OpenPGPComponentSignature sig )
2851
2905
{
2852
2906
return new OpenPGPSignatureChain (Link .create (sig ));
2853
2907
}
2854
2908
2909
+ /**
2910
+ * Return the very first link in the chain.
2911
+ * This is typically a link that originates from the issuing certificates primary key.
2912
+ *
2913
+ * @return root link
2914
+ */
2855
2915
public Link getRootLink ()
2856
2916
{
2857
2917
return chainLinks .get (0 );
2858
2918
}
2859
2919
2920
+ /**
2921
+ * Return the issuer of the root link. This is typically the issuing certificates primary key.
2922
+ *
2923
+ * @return root links issuer
2924
+ */
2860
2925
public OpenPGPComponentKey getRootLinkIssuer ()
2861
2926
{
2862
2927
return getRootLink ().getSignature ().getIssuer ();
2863
2928
}
2864
2929
2930
+ /**
2931
+ * Return the last link in the chain, which applies to the chains target component.
2932
+ *
2933
+ * @return leaf link
2934
+ */
2865
2935
public Link getLeafLink ()
2866
2936
{
2867
2937
return chainLinks .get (chainLinks .size () - 1 );
2868
2938
}
2869
2939
2940
+ /**
2941
+ * Return the {@link OpenPGPComponentKey} to which the leaf link applies to.
2942
+ * For subkey binding signatures, this is the subkey.
2943
+ * For user-id certification signatures, it is the primary key.
2944
+ *
2945
+ * @return target key component of the leaf link
2946
+ */
2870
2947
public OpenPGPComponentKey getLeafLinkTargetKey ()
2871
2948
{
2872
2949
return getSignature ().getTargetKeyComponent ();
2873
2950
}
2874
2951
2952
+ /**
2953
+ * Return true, if the chain only consists of non-revocation signatures and is therefore a certification chain.
2954
+ *
2955
+ * @return true if the chain is a certification, false if it contains a revocation link.
2956
+ */
2875
2957
public boolean isCertification ()
2876
2958
{
2877
2959
for (Link link : chainLinks )
@@ -2884,6 +2966,11 @@ public boolean isCertification()
2884
2966
return true ;
2885
2967
}
2886
2968
2969
+ /**
2970
+ * Return true, if the chain contains at least one revocation signature.
2971
+ *
2972
+ * @return true if the chain is a revocation.
2973
+ */
2887
2974
public boolean isRevocation ()
2888
2975
{
2889
2976
for (Link link : chainLinks )
@@ -2896,6 +2983,11 @@ public boolean isRevocation()
2896
2983
return false ;
2897
2984
}
2898
2985
2986
+ /**
2987
+ * Return true, if the chain contains at least one link that represents a hard revocation.
2988
+ *
2989
+ * @return true if chain is hard revocation, false if it is a certification or soft revocation
2990
+ */
2899
2991
public boolean isHardRevocation ()
2900
2992
{
2901
2993
for (Link link : chainLinks )
@@ -2945,6 +3037,13 @@ public Date getUntil()
2945
3037
return soonestExpiration ;
2946
3038
}
2947
3039
3040
+ /**
3041
+ * Return true if the chain is effective at the given evaluation date, meaning all link signatures have
3042
+ * been created before the evaluation time, and none signature expires before the evaluation time.
3043
+ *
3044
+ * @param evaluationDate reference time
3045
+ * @return true if chain is effective at evaluation date
3046
+ */
2948
3047
public boolean isEffectiveAt (Date evaluationDate )
2949
3048
{
2950
3049
if (isHardRevocation ())
@@ -2957,6 +3056,12 @@ public boolean isEffectiveAt(Date evaluationDate)
2957
3056
return !evaluationDate .before (since ) && (until == null || !evaluationDate .after (until ));
2958
3057
}
2959
3058
3059
+ /**
3060
+ * Return true if the signature chain is valid, meaning all its chain links are valid.
3061
+ *
3062
+ * @return true if chain is valid
3063
+ * @throws PGPSignatureException if an exception occurs during signature verification
3064
+ */
2960
3065
public boolean isValid ()
2961
3066
throws PGPSignatureException
2962
3067
{
@@ -2969,6 +3074,14 @@ public boolean isValid()
2969
3074
return isValid (cert .implementation .pgpContentVerifierBuilderProvider (), cert .policy );
2970
3075
}
2971
3076
3077
+ /**
3078
+ * Return true if the signature chain is valid, meaning all its chain links are valid.
3079
+ *
3080
+ * @param contentVerifierBuilderProvider provider for content verifier builders
3081
+ * @param policy algorithm policy
3082
+ * @return true if chain is valid
3083
+ * @throws PGPSignatureException if an exception occurs during signature verification
3084
+ */
2972
3085
public boolean isValid (PGPContentVerifierBuilderProvider contentVerifierBuilderProvider , OpenPGPPolicy policy )
2973
3086
throws PGPSignatureException
2974
3087
{
@@ -3056,11 +3169,24 @@ public Link(OpenPGPComponentSignature signature)
3056
3169
this .signature = signature ;
3057
3170
}
3058
3171
3172
+ /**
3173
+ * Return the {@link Date} since when the link is effective.
3174
+ * This is the creation time of the signature.
3175
+ *
3176
+ * @return signature creation time
3177
+ */
3059
3178
public Date since ()
3060
3179
{
3061
3180
return signature .getCreationTime ();
3062
3181
}
3063
3182
3183
+ /**
3184
+ * Return the {@link Date} until the signature is effective.
3185
+ * This is, depending on which event is earlier in time, either the signature expiration time,
3186
+ * or the key expiration time.
3187
+ *
3188
+ * @return time until the link is valid
3189
+ */
3064
3190
public Date until ()
3065
3191
{
3066
3192
Date backSigExpiration = getBackSigExpirationTime ();
@@ -3078,6 +3204,11 @@ public Date until()
3078
3204
return backSigExpiration ;
3079
3205
}
3080
3206
3207
+ /**
3208
+ * Return the expiration time of the primary key binding signature.
3209
+ *
3210
+ * @return primary key binding signature expiration time
3211
+ */
3081
3212
private Date getBackSigExpirationTime ()
3082
3213
{
3083
3214
if (signature .getSignature ().getSignatureType () != PGPSignature .SUBKEY_BINDING )
@@ -3116,6 +3247,14 @@ private Date getBackSigExpirationTime()
3116
3247
}
3117
3248
}
3118
3249
3250
+ /**
3251
+ * Verify the link signature.
3252
+ *
3253
+ * @param contentVerifierBuilderProvider provider for content verifier builders
3254
+ * @param policy algorithm policy
3255
+ * @return true if the signature is valid, false otherwise
3256
+ * @throws PGPSignatureException if an exception occurs during signature verification
3257
+ */
3119
3258
public boolean verify (PGPContentVerifierBuilderProvider contentVerifierBuilderProvider ,
3120
3259
OpenPGPPolicy policy )
3121
3260
throws PGPSignatureException
@@ -3130,6 +3269,14 @@ public String toString()
3130
3269
return signature .toString ();
3131
3270
}
3132
3271
3272
+ /**
3273
+ * Factory method for creating Links from component signatures.
3274
+ * Returns either a {@link Certification} in case the signature is a binding,
3275
+ * or a {@link Revocation} in case the signature is a revocation signature.
3276
+ *
3277
+ * @param signature component signature
3278
+ * @return link
3279
+ */
3133
3280
public static Link create (OpenPGPComponentSignature signature )
3134
3281
{
3135
3282
if (signature .isRevocation ())
@@ -3142,6 +3289,11 @@ public static Link create(OpenPGPComponentSignature signature)
3142
3289
}
3143
3290
}
3144
3291
3292
+ /**
3293
+ * Return the signature of the link.
3294
+ *
3295
+ * @return signature
3296
+ */
3145
3297
public OpenPGPComponentSignature getSignature ()
3146
3298
{
3147
3299
return signature ;
@@ -3218,18 +3370,29 @@ public OpenPGPSignatureChains(OpenPGPCertificateComponent component)
3218
3370
3219
3371
/**
3220
3372
* Add a single chain to the collection.
3373
+ *
3221
3374
* @param chain chain
3222
3375
*/
3223
3376
public void add (OpenPGPSignatureChain chain )
3224
3377
{
3225
3378
this .chains .add (chain );
3226
3379
}
3227
3380
3381
+ /**
3382
+ * Add all chains to the collection.
3383
+ *
3384
+ * @param otherChains other chains
3385
+ */
3228
3386
public void addAll (OpenPGPSignatureChains otherChains )
3229
3387
{
3230
3388
this .chains .addAll (otherChains .chains );
3231
3389
}
3232
3390
3391
+ /**
3392
+ * Return true if the collection is empty.
3393
+ *
3394
+ * @return true if empty
3395
+ */
3233
3396
public boolean isEmpty ()
3234
3397
{
3235
3398
return chains .isEmpty ();
@@ -3254,6 +3417,12 @@ public OpenPGPSignatureChain getCertificationAt(Date evaluationTime)
3254
3417
return null ;
3255
3418
}
3256
3419
3420
+ /**
3421
+ * Return all {@link OpenPGPSignatureChain} objects, which are valid at the given evaluation time.
3422
+ *
3423
+ * @param evaluationTime reference time
3424
+ * @return valid chains at reference time
3425
+ */
3257
3426
public OpenPGPSignatureChains getChainsAt (Date evaluationTime )
3258
3427
{
3259
3428
OpenPGPSignatureChains effectiveChains = new OpenPGPSignatureChains (targetComponent );
@@ -3269,6 +3438,7 @@ public OpenPGPSignatureChains getChainsAt(Date evaluationTime)
3269
3438
3270
3439
/**
3271
3440
* Return a negative certification chain for the component for the given evaluationTime.
3441
+ *
3272
3442
* @param evaluationTime time for which revocation-ness of the {@link OpenPGPCertificateComponent} is checked.
3273
3443
* @return negative certification chain or null
3274
3444
*/
@@ -3301,6 +3471,12 @@ public String toString()
3301
3471
return b .toString ();
3302
3472
}
3303
3473
3474
+ /**
3475
+ * Return all {@link OpenPGPSignatureChain} items which originate from the root {@link OpenPGPComponentKey}.
3476
+ *
3477
+ * @param root root key
3478
+ * @return all chains with root key as origin
3479
+ */
3304
3480
public OpenPGPSignatureChains fromOrigin (OpenPGPComponentKey root )
3305
3481
{
3306
3482
OpenPGPSignatureChains chainsFromRoot = new OpenPGPSignatureChains (root );
@@ -3315,6 +3491,12 @@ public OpenPGPSignatureChains fromOrigin(OpenPGPComponentKey root)
3315
3491
return chainsFromRoot ;
3316
3492
}
3317
3493
3494
+ /**
3495
+ * Return the latest chain, which is valid at the given evaluation time.
3496
+ *
3497
+ * @param evaluationDate reference time
3498
+ * @return latest valid chain
3499
+ */
3318
3500
public OpenPGPSignatureChain getChainAt (Date evaluationDate )
3319
3501
{
3320
3502
OpenPGPSignatureChains atDate = getChainsAt (evaluationDate );
0 commit comments