2019-05-23 01:31:11 +08:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
2019-07-11 05:54:14 +08:00
|
|
|
"fmt"
|
2019-07-13 04:04:56 +08:00
|
|
|
"os"
|
2019-05-23 01:31:11 +08:00
|
|
|
)
|
|
|
|
|
2019-08-02 07:05:47 +08:00
|
|
|
// WeakRsaKeyEnv is an environment variable which, when set, lowers the
|
2019-07-13 04:04:56 +08:00
|
|
|
// minimum required bits of RSA keys to 512. This should be used exclusively in
|
|
|
|
// test situations.
|
2019-08-02 07:05:47 +08:00
|
|
|
const WeakRsaKeyEnv = "LIBP2P_ALLOW_WEAK_RSA_KEYS"
|
2019-07-13 04:04:56 +08:00
|
|
|
|
|
|
|
var MinRsaKeyBits = 2048
|
2019-07-11 05:54:14 +08:00
|
|
|
|
2019-05-23 01:31:11 +08:00
|
|
|
// ErrRsaKeyTooSmall is returned when trying to generate or parse an RSA key
|
2019-07-13 04:04:56 +08:00
|
|
|
// that's smaller than MinRsaKeyBits bits. In test
|
|
|
|
var ErrRsaKeyTooSmall error
|
|
|
|
|
|
|
|
func init() {
|
2019-08-02 07:05:47 +08:00
|
|
|
if _, ok := os.LookupEnv(WeakRsaKeyEnv); ok {
|
2019-07-13 04:04:56 +08:00
|
|
|
MinRsaKeyBits = 512
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrRsaKeyTooSmall = fmt.Errorf("rsa keys must be >= %d bits to be useful", MinRsaKeyBits)
|
|
|
|
}
|