|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package config |
| 18 | + |
| 19 | +// NewJweCryptoConfig returns a CryptoConfig that contains the required configuration for using |
| 20 | +// the jwe keyunwrap interface |
| 21 | +func NewJweCryptoConfig(pubKey *[]byte, privKey *[]byte, privKeyPassword *string) CryptoConfig { |
| 22 | + pubKeys := [][]byte{} |
| 23 | + privKeys := [][]byte{} |
| 24 | + privKeysPasswords := [][]byte{} |
| 25 | + |
| 26 | + if pubKey != nil { |
| 27 | + pubKeys = append(pubKeys, *pubKey) |
| 28 | + } |
| 29 | + if privKey != nil { |
| 30 | + privKeys = append(privKeys, *privKey) |
| 31 | + } |
| 32 | + if privKeyPassword != nil { |
| 33 | + privKeysPasswords = append(privKeysPasswords, []byte(*privKeyPassword)) |
| 34 | + } |
| 35 | + |
| 36 | + dc := DecryptConfig{ |
| 37 | + Parameters: map[string][][]byte{ |
| 38 | + "privkeys": privKeys, |
| 39 | + "privkeys-passwords": privKeysPasswords, |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + ep := map[string][][]byte{ |
| 44 | + "pubkeys": pubKeys, |
| 45 | + } |
| 46 | + |
| 47 | + return CryptoConfig{ |
| 48 | + EncryptConfig: &EncryptConfig{ |
| 49 | + Parameters: ep, |
| 50 | + DecryptConfig: dc, |
| 51 | + }, |
| 52 | + DecryptConfig: &dc, |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// NewPkcs7CryptoConfig returns a CryptoConfig that contains the required configuration for using |
| 57 | +// the pkcs7 keyunwrap interface |
| 58 | +func NewPkcs7CryptoConfig(x509 *[]byte, privKey *[]byte, privKeyPassword *string) CryptoConfig { |
| 59 | + x509s := [][]byte{} |
| 60 | + privKeys := [][]byte{} |
| 61 | + privKeysPasswords := [][]byte{} |
| 62 | + |
| 63 | + if x509 != nil { |
| 64 | + x509s = append(x509s, *x509) |
| 65 | + } |
| 66 | + if privKey != nil { |
| 67 | + privKeys = append(privKeys, *privKey) |
| 68 | + } |
| 69 | + if privKeyPassword != nil { |
| 70 | + privKeysPasswords = append(privKeysPasswords, []byte(*privKeyPassword)) |
| 71 | + } |
| 72 | + |
| 73 | + dc := DecryptConfig{ |
| 74 | + Parameters: map[string][][]byte{ |
| 75 | + "privkeys": privKeys, |
| 76 | + "privkeys-passwords": privKeysPasswords, |
| 77 | + }, |
| 78 | + } |
| 79 | + |
| 80 | + ep := map[string][][]byte{ |
| 81 | + "x509s": x509s, |
| 82 | + } |
| 83 | + |
| 84 | + return CryptoConfig{ |
| 85 | + EncryptConfig: &EncryptConfig{ |
| 86 | + Parameters: ep, |
| 87 | + DecryptConfig: dc, |
| 88 | + }, |
| 89 | + DecryptConfig: &dc, |
| 90 | + } |
| 91 | +} |
0 commit comments