| 1 | package WWW::LetsEncrypt::JWK; | ||
| 2 | 10 | $WWW::LetsEncrypt::JWK::VERSION = '0.001'; | |
| 3 | 10 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 10 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 10 | ▶ | use Carp qw(confess); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 10 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 10 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 10 | has 'key_type' => ( | |
| 12 | is => 'ro', | ||
| 13 | isa => 'Str', | ||
| 14 | required => 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | 10 | has '_RefObj' => ( | |
| 18 | is => 'ro', | ||
| 19 | isa => 'Object', | ||
| 20 | ); | ||
| 21 | |||
| 22 | 10 | requires 'generate_new'; | |
| 23 | 10 | requires 'load_cert'; | |
| 24 | 10 | requires 'load_parameters'; | |
| 25 | 10 | requires 'get_privatekey_string'; | |
| 26 | 10 | requires 'sign'; | |
| 27 | 10 | requires 'thumbprint'; | |
| 28 | 10 | requires '_get_public_key_components'; | |
| 29 | |||
| 30 | sub serialize_public_key { | ||
| 31 | 7 | ▶ | my ($self) = @_; |
|
Subroutine
serialize_public_key: called CC=1 SCAR=0.0
Pod
documented
| |||
| 32 | 7 | my %jwk = $self->_get_public_key_components(); | |
| 33 | 7 | $jwk{kty} = $self->key_type; | |
| 34 | |||
| 35 | 7 | return \%jwk; | |
| 36 | } | ||
| 37 | |||
| 38 | 10 | 1; | |
| 39 | |||
| 40 | __END__ | ||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | WWW::LetsEncrypt::JWK; | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use Moose; | ||
| 51 | |||
| 52 | extends qw(WWW::LetsEncrypt::JWK); | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | =head1 DESCRIPTION | ||
| 57 | |||
| 58 | This is a role that when used together with WWW::LetsEncrypt::JWA as parents | ||
| 59 | will create a JSON Web Key that implements all of the functions needed for | ||
| 60 | signing JSON Web Signature objects. Specifically, this role deals with storing | ||
| 61 | the key object and its parameters. | ||
| 62 | |||
| 63 | =head2 Attributes | ||
| 64 | |||
| 65 | 'key_type' a scalar attribute necessary for holding what the key type may be. | ||
| 66 | The permitted key types should be either: ECDSA, RSA, or HMAC (as per the RFC | ||
| 67 | and our restriction). | ||
| 68 | |||
| 69 | '_RefObj' a private object attribute meant to hold the concrete implementation | ||
| 70 | of the key type. Eg: a Crypt::OpenSSL::RSA object is held here for JWK::RSA, | ||
| 71 | and it is used to perform signing (and all associated necessities, such as | ||
| 72 | padding). | ||
| 73 | |||
| 74 | =head2 Public Functions | ||
| 75 | |||
| 76 | =over 4 | ||
| 77 | |||
| 78 | =item generate_new | ||
| 79 | |||
| 80 | This function, when implemented, should create a new JSON Web Key of a specific algorithm type. | ||
| 81 | |||
| 82 | Input | ||
| 83 | |||
| 84 | $number - key_length | ||
| 85 | $string - key id | ||
| 86 | |||
| 87 | Output | ||
| 88 | |||
| 89 | JWK Object | ||
| 90 | |||
| 91 | =item get_privatekey_string | ||
| 92 | |||
| 93 | This function, when implemented, should return the PKCS#1 encoding of the private key. | ||
| 94 | |||
| 95 | Output | ||
| 96 | |||
| 97 | Scalar string that is the PKCS#1 representation of the RSA private key. | ||
| 98 | |||
| 99 | =item load_cert | ||
| 100 | |||
| 101 | This function, when implemented, should accept a private key string as a parameter and return new JSON Web Key. | ||
| 102 | |||
| 103 | Input | ||
| 104 | |||
| 105 | { | ||
| 106 | private_key => $scalar string of the private key to use, | ||
| 107 | } | ||
| 108 | |||
| 109 | Output | ||
| 110 | |||
| 111 | JWK Object | ||
| 112 | |||
| 113 | =item load_parameters | ||
| 114 | |||
| 115 | This function, when implemented, should accept a private key as per the serialized parameters from JWK and return new JSON Web Key. | ||
| 116 | |||
| 117 | Input | ||
| 118 | |||
| 119 | { | ||
| 120 | parameters => \%hash_ref of parameters that are base64url encoded, | ||
| 121 | } | ||
| 122 | |||
| 123 | Output | ||
| 124 | |||
| 125 | JWK Object | ||
| 126 | |||
| 127 | =item serialize_public_key | ||
| 128 | |||
| 129 | Object method, with _get_public_key_components implemented, returns a valid serialization of a JWK's public key. | ||
| 130 | |||
| 131 | Input | ||
| 132 | |||
| 133 | $self | ||
| 134 | |||
| 135 | Output | ||
| 136 | |||
| 137 | \%hash_ref that is the public key components | ||
| 138 | |||
| 139 | =item sign | ||
| 140 | |||
| 141 | When implemented, the function takes a single parameter that is the digested value, and returns a signed string. | ||
| 142 | |||
| 143 | Input | ||
| 144 | |||
| 145 | $scalar string of digested data. | ||
| 146 | |||
| 147 | Output | ||
| 148 | |||
| 149 | $scalar string of signed digested data. | ||
| 150 | |||
| 151 | =item thumbprint | ||
| 152 | |||
| 153 | Object method that returns the rfc7638 JWK thumbprint for the key. | ||
| 154 | |||
| 155 | Output | ||
| 156 | |||
| 157 | $scalar string that is the thumbprint of the key | ||
| 158 | |||
| 159 | =back | ||
| 160 | |||
| 161 | =head2 Private Functions | ||
| 162 | |||
| 163 | =over 4 | ||
| 164 | |||
| 165 | =item _get_public_key_components | ||
| 166 | |||
| 167 | Abstract object function which should return a hash of public key parameters (see the RFC) | ||
| 168 | |||
| 169 | Input | ||
| 170 | |||
| 171 | $self - Object Reference | ||
| 172 | |||
| 173 | Output | ||
| 174 | |||
| 175 | %hash of the public key parameters | ||
| 176 | |||
| 177 | =back | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||