File tree 3 files changed +20
-6
lines changed
3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 15
15
16
16
extern crate clap;
17
17
extern crate sigstore;
18
+ use base64:: { engine:: general_purpose:: STANDARD as BASE64_STD_ENGINE , Engine as _} ;
18
19
use clap:: Parser ;
19
20
use sigstore:: cosign:: client:: Client ;
20
21
use sigstore:: cosign:: CosignCapabilities ;
@@ -56,11 +57,17 @@ pub async fn main() {
56
57
. with ( fmt:: layer ( ) . with_writer ( std:: io:: stderr) )
57
58
. init ( ) ;
58
59
59
- let certificate = fs:: read_to_string ( & cli. certificate ) . expect ( "error reading certificate" ) ;
60
+ // certificate may be PEM or "double base64 encoded PEM" (cosign).
61
+ let cert_input = fs:: read_to_string ( & cli. certificate ) . expect ( "error reading certificate" ) ;
62
+ let certificate = match BASE64_STD_ENGINE . decode ( cert_input. clone ( ) ) {
63
+ Ok ( res) => String :: from_utf8 ( res) . expect ( "error stringifying PEM certificate" ) ,
64
+ Err ( _) => cert_input,
65
+ } ;
66
+
60
67
let signature = fs:: read_to_string ( & cli. signature ) . expect ( "error reading signature" ) ;
61
68
let blob = fs:: read ( cli. blob . as_str ( ) ) . expect ( "error reading blob file" ) ;
62
69
63
- match Client :: verify_blob ( & certificate, & signature, & blob) {
70
+ match Client :: verify_blob ( & certificate, signature. trim ( ) , & blob) {
64
71
Ok ( _) => println ! ( "Verification succeeded" ) ,
65
72
Err ( e) => eprintln ! ( "Verification failed {:?}" , e) ,
66
73
}
Original file line number Diff line number Diff line change 13
13
// See the License for the specific language governing permissions and
14
14
// limitations under the License.
15
15
16
+ use base64:: { engine:: general_purpose:: STANDARD as BASE64_STD_ENGINE , Engine as _} ;
16
17
use clap:: Parser ;
17
18
use sigstore:: cosign:: bundle:: SignedArtifactBundle ;
18
19
use sigstore:: cosign:: client:: Client ;
@@ -62,7 +63,14 @@ pub async fn main() {
62
63
let blob = fs:: read ( cli. blob . as_str ( ) ) . expect ( "error reading blob file" ) ;
63
64
64
65
let bundle = SignedArtifactBundle :: new_verified ( & bundle_json, & rekor_pub_key) . unwrap ( ) ;
65
- match Client :: verify_blob ( & bundle. cert , & bundle. base64_signature , & blob) {
66
+
67
+ // certificate in bundle is double base64 encoded, remove one layer:
68
+ let cert_data = BASE64_STD_ENGINE
69
+ . decode ( bundle. cert )
70
+ . expect ( "Error decoding base64 certificate" ) ;
71
+ let cert = String :: from_utf8 ( cert_data) . expect ( "error stringifying PEM certificate" ) ;
72
+
73
+ match Client :: verify_blob ( & cert, & bundle. base64_signature , & blob) {
66
74
Ok ( _) => println ! ( "Verification succeeded" ) ,
67
75
Err ( e) => eprintln ! ( "Verification failed: {}" , e) ,
68
76
}
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ use crate::registry::{Auth, PushResponse};
46
46
47
47
use crate :: crypto:: { CosignVerificationKey , Signature } ;
48
48
use crate :: errors:: SigstoreError ;
49
- use base64:: { engine:: general_purpose:: STANDARD as BASE64_STD_ENGINE , Engine as _} ;
50
49
use pkcs8:: der:: Decode ;
51
50
use x509_cert:: Certificate ;
52
51
@@ -155,13 +154,13 @@ pub trait CosignCapabilities {
155
154
/// Verifies the signature produced by cosign when signing the given blob via the `cosign sign-blob` command
156
155
///
157
156
/// The parameters:
158
- /// * `cert`: a PEM encoded x509 certificate that contains the public key used to verify the signature
157
+ /// * `cert`: a PEM encoded x509 certificate that contains the public key used to verify the signature.
158
+ /// Note that cert is not double-base64-encoded like the output of sigstore/cosign is.
159
159
/// * `signature`: the base64 encoded signature of the blob that has to be verified
160
160
/// * `blob`: the contents of the blob
161
161
///
162
162
/// This function returns `Ok())` when the given signature has been verified, otherwise returns an `Err`.
163
163
fn verify_blob ( cert : & str , signature : & str , blob : & [ u8 ] ) -> Result < ( ) > {
164
- let cert = BASE64_STD_ENGINE . decode ( cert) ?;
165
164
let pem = pem:: parse ( cert) ?;
166
165
let cert = Certificate :: from_der ( pem. contents ( ) ) . map_err ( |e| {
167
166
SigstoreError :: PKCS8SpkiError ( format ! ( "parse der into cert failed: {e}" ) )
You can’t perform that action at this time.
0 commit comments