-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.go
115 lines (80 loc) · 3.55 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package gramine_ratls
import (
"fmt"
)
type ErrorCode int
// Error codes are standard MBEDTLS error code found here:
// https://github.com/Mbed-TLS/mbedtls/blob/development/include/mbedtls/x509.h
const (
// Fatal error occured, not able to load RATLS libraries
RATLS_WRAPPER_ERR_LIB_LOAD_FAILED ErrorCode = -0x0001
// Invalid path
RATLS_WRAPPER_ERR_PATH_INVALID ErrorCode = -0x0002
// Invalid arguments, e.g. certificate is empty
RATLS_WRAPPER_ERR_INVALID_ARGS ErrorCode = -0x0003
// Certificate creation failed
RATLS_WRAPPER_ERR_CERTIFICATE_CREATION_FAILED ErrorCode = -0x0004
// Invalid SGX Attestation file
RATLS_WRAPPER_ERR_SGX_ATTESTATION_FILE ErrorCode = -0x0005
// Invalid certificate
RATLS_WRAPPER_ERR_INVALID_CERT ErrorCode = -0x0006
// Certificate decoding failed
RATLS_WRAPPER_ERR_CERT_DECODE_FAILED ErrorCode = -0x0007
// Entropy Source Failed
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ErrorCode = -0x0034
// The CRT/CRL/CSR format is invalid, e.g. different type expected.
MBEDTLS_ERR_X509_INVALID_FORMAT ErrorCode = -0x2180
// The extension tag or value is invalid.
MBEDTLS_ERR_X509_INVALID_EXTENSIONS ErrorCode = -0x2500
// Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid)
MBEDTLS_ERR_X509_SIG_MISMATCH ErrorCode = -0x2680
// Certificate verification failed, e.g. CRL, CA or signature check failed.
MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ErrorCode = -0x2700
// Allocation of memory failed.
MBEDTLS_ERR_X509_ALLOC_FAILED ErrorCode = -0x2880
// A fatal error occurred, eg the chain is too long or the vrfy callback failed.
MBEDTLS_ERR_X509_FATAL_ERROR ErrorCode = -0x3000
// Bad input parameters to function.
MBEDTLS_ERR_PK_BAD_INPUT_DATA ErrorCode = -0x3E80
// Memory Allocation Failed
MBEDTLS_ERR_PK_ALLOC_FAILED ErrorCode = -0x3F80
)
// Error Message returns the status code message
func (o ErrorCode) Error() string {
switch o {
case RATLS_WRAPPER_ERR_LIB_LOAD_FAILED:
return fmt.Sprintf("RATLS library loading failed: %d", o)
case RATLS_WRAPPER_ERR_PATH_INVALID:
return fmt.Sprintf("Invalid path format: %d", o)
case RATLS_WRAPPER_ERR_INVALID_ARGS:
return fmt.Sprintf("Invalid args: %d", o)
case RATLS_WRAPPER_ERR_CERTIFICATE_CREATION_FAILED:
return fmt.Sprintf("Certificate creation failed: %d", o)
case RATLS_WRAPPER_ERR_SGX_ATTESTATION_FILE:
return fmt.Sprintf("SGX RA-TLS attestation type file '/dev/attestation/attestation_type' not found: %d", o)
case RATLS_WRAPPER_ERR_INVALID_CERT:
return fmt.Sprintf("Invalid certificate: %d", o)
case RATLS_WRAPPER_ERR_CERT_DECODE_FAILED:
return fmt.Sprintf("failed to decode PEM certificate: %d", o)
case MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED:
return fmt.Sprintf("Entropy Source Failed: %d", o)
case MBEDTLS_ERR_X509_INVALID_FORMAT:
return fmt.Sprintf("The CRT/CRL/CSR format is invalid: %d", o)
case MBEDTLS_ERR_X509_INVALID_EXTENSIONS:
return fmt.Sprintf("The extension tag or value is invalid: %d", o)
case MBEDTLS_ERR_X509_SIG_MISMATCH:
return fmt.Sprintf("Signature algorithms do not match: %d", o)
case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
return fmt.Sprintf("Certificate verification failed: %d", o)
case MBEDTLS_ERR_X509_ALLOC_FAILED:
return fmt.Sprintf("Allocation of memory failed: %d", o)
case MBEDTLS_ERR_X509_FATAL_ERROR:
return fmt.Sprintf("A fatal error occurred: %d", o)
case MBEDTLS_ERR_PK_BAD_INPUT_DATA:
return fmt.Sprintf("Bad input parameters to function: %d", o)
case MBEDTLS_ERR_PK_ALLOC_FAILED:
return fmt.Sprintf("Memory Allocation Failed: %d", o)
default:
return fmt.Sprintf("UNKNOWN: %d", o)
}
}