-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bingocloud):improve bingocloud driver
- Loading branch information
李锐
committed
May 18, 2023
1 parent
3a7171b
commit a8522f5
Showing
57 changed files
with
785 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ type DiskCreateConfig struct { | |
SizeGb int | ||
Desc string | ||
ProjectId string | ||
ZoneId string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
package bingocloud | ||
|
||
import ( | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"encoding/base64" | ||
"fmt" | ||
"unicode/utf8" | ||
) | ||
|
||
type SAccount struct { | ||
AccessKeyId string | ||
SecretAccessKey string | ||
Arn string | ||
DeptId string | ||
DeptName string | ||
IsEncrypted string | ||
UserId string | ||
UserName string | ||
Id string `json:"Id"` | ||
AccessKeyId string `json:"AccessKeyId"` | ||
Arn string `json:"Arn"` | ||
FullName string `json:"FullName"` | ||
IsAdmin string `json:"IsAdmin"` | ||
IsEncrypted string `json:"IsEncrypted"` | ||
SecurityKey string `json:"SecurityKey"` | ||
Status string `json:"Status"` | ||
Type string `json:"Type"` | ||
UserId string `json:"UserId"` | ||
UserName string `json:"UserName"` | ||
} | ||
|
||
func (self *SAccount) decryptKeys(masterSecretKey string) (string, string) { | ||
if len(self.SecurityKey) == len(masterSecretKey) { | ||
return self.AccessKeyId, self.SecurityKey | ||
} | ||
|
||
secretKeyBytes, err := base64.StdEncoding.DecodeString(self.SecurityKey) | ||
if err != nil { | ||
return "", "" | ||
} | ||
var adminSecretKey = "" | ||
if len(masterSecretKey) >= 32 { | ||
adminSecretKey = masterSecretKey[0:32] | ||
} else { | ||
adminSecretKey = fmt.Sprintf("%s%032s", masterSecretKey, "")[0:32] | ||
} | ||
decryptVal, err := aesCrtCrypt([]byte(secretKeyBytes), []byte(adminSecretKey), make([]byte, 16)) | ||
if err != nil { | ||
return "", "" | ||
} | ||
|
||
decryptSecret := fmt.Sprintf("%s", decryptVal) | ||
|
||
if !utf8.ValidString(decryptSecret) { | ||
return self.AccessKeyId, self.SecurityKey | ||
} | ||
|
||
return self.AccessKeyId, decryptSecret | ||
} | ||
|
||
func aesCrtCrypt(val, key, iv []byte) ([]byte, error) { | ||
block, err := aes.NewCipher(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
blockMode := cipher.NewCTR(block, iv) | ||
body := make([]byte, len(val)) | ||
blockMode.XORKeyStream(body, val) | ||
return body, nil | ||
} |
Oops, something went wrong.