1 // 2 // Copyright (c) SAS Institute Inc. 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 token 18 19 import ( 20 "crypto" 21 "crypto/x509" 22 "io" 23 24 "github.com/sassoftware/relic/config" 25 ) 26 27 type KeyType uint 28 29 const ( 30 // Values match CKK_RSA etc. 31 KeyTypeRsa KeyType = 0 32 KeyTypeEcdsa KeyType = 3 33 ) 34 35 type Token interface { 36 io.Closer 37 // Check that the token is still alive 38 Ping() error 39 // Return the token config object used to instantiate this token 40 Config() *config.TokenConfig 41 // Get a key from the token by its config alias 42 GetKey(keyName string) (Key, error) 43 // Import a public+private keypair into the token 44 Import(keyName string, privKey crypto.PrivateKey) (Key, error) 45 // Import an issuer certificate into the token. The new object label will 46 // be labelBase plus the fingerprint of the certificate. 47 ImportCertificate(cert *x509.Certificate, labelBase string) error 48 // Generate a new key in the token 49 Generate(keyName string, keyType KeyType, bits uint) (Key, error) 50 // Print key info 51 ListKeys(opts ListOptions) error 52 } 53 54 type Key interface { 55 crypto.Signer 56 // Return the key config object used to instantiate this key 57 Config() *config.KeyConfig 58 // Get the CKK_ID or equivalent for the key 59 GetID() []byte 60 // Import a leaf certificate for this key 61 ImportCertificate(cert *x509.Certificate) error 62 } 63 64 type ListOptions struct { 65 // Destination stream 66 Output io.Writer 67 // Filter by attributes 68 Label string 69 ID string 70 // Print key and certificate contents 71 Values bool 72 } 73