diff options
author | Unknwon <u@gogs.io> | 2015-03-25 08:59:48 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-25 08:59:48 -0400 |
commit | aae74c793ae859baabead8cebdc760455fb39038 (patch) | |
tree | b1c671ec2466b0f87ceae48a436e88cae521ee7f /models/publickey.go | |
parent | 5169a0e025d5e250b9bd3b8a194ab7dc6dde32a3 (diff) | |
download | gitea-aae74c793ae859baabead8cebdc760455fb39038.tar.gz gitea-aae74c793ae859baabead8cebdc760455fb39038.zip |
#1133 add config option [service] DISABLE_MINIMUM_KEY_SIZE_CHECK
Diffstat (limited to 'models/publickey.go')
-rw-r--r-- | models/publickey.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/models/publickey.go b/models/publickey.go index f6cd5b4cbb..0db9f333be 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -101,17 +101,15 @@ func (key *PublicKey) GetAuthorizedString() string { return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, key.Id, setting.CustomConf, key.Content) } -var ( - MinimumKeySize = map[string]int{ - "(ED25519)": 256, - "(ECDSA)": 256, - "(NTRU)": 1087, - "(MCE)": 1702, - "(McE)": 1702, - "(RSA)": 2048, - "(DSA)": 1024, - } -) +var minimumKeySizes = map[string]int{ + "(ED25519)": 256, + "(ECDSA)": 256, + "(NTRU)": 1087, + "(MCE)": 1702, + "(McE)": 1702, + "(RSA)": 2048, + "(DSA)": 1024, +} func extractTypeFromBase64Key(key string) (string, error) { b, err := base64.StdEncoding.DecodeString(key) @@ -228,15 +226,17 @@ func CheckPublicKeyString(content string) (bool, error) { } // Check if key type and key size match. - keySize := com.StrTo(sshKeygenOutput[0]).MustInt() - if keySize == 0 { - return false, errors.New("cannot get key size of the given key") - } - keyType := strings.TrimSpace(sshKeygenOutput[len(sshKeygenOutput)-1]) - if minimumKeySize := MinimumKeySize[keyType]; minimumKeySize == 0 { - return false, errors.New("sorry, unrecognized public key type") - } else if keySize < minimumKeySize { - return false, fmt.Errorf("the minimum accepted size of a public key %s is %d", keyType, minimumKeySize) + if !setting.Service.DisableMinimumKeySizeCheck { + keySize := com.StrTo(sshKeygenOutput[0]).MustInt() + if keySize == 0 { + return false, errors.New("cannot get key size of the given key") + } + keyType := strings.TrimSpace(sshKeygenOutput[len(sshKeygenOutput)-1]) + if minimumKeySize := minimumKeySizes[keyType]; minimumKeySize == 0 { + return false, errors.New("sorry, unrecognized public key type") + } else if keySize < minimumKeySize { + return false, fmt.Errorf("the minimum accepted size of a public key %s is %d", keyType, minimumKeySize) + } } return true, nil |