You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
689 B
31 lines
689 B
3 years ago
|
package chromium
|
||
|
|
||
|
import (
|
||
|
"encoding/base64"
|
||
|
"errors"
|
||
|
|
||
|
"github.com/smallstep/cli/utils"
|
||
|
"github.com/tidwall/gjson"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||
|
)
|
||
|
|
||
|
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||
|
keyFile, err := utils.ReadFile(item.TempChromiumKey)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
|
||
|
if encryptedKey.Exists() {
|
||
|
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
||
|
if err != nil {
|
||
|
return nil, errDecodeMasterKeyFailed
|
||
|
}
|
||
|
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:])
|
||
|
return c.browserInfo.masterKey, err
|
||
|
}
|
||
|
return nil, nil
|
||
|
}
|