Skip to content
Snippets Groups Projects
Commit 42e4fcba authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

base64 password support

parent 72043105
Branches
Tags
3 merge requests!231Revert "Update store to print changes to the partners list",!187Xx 3829/triggers,!184Cleanup for ResetSession
...@@ -525,7 +525,7 @@ func createClient() *api.Client { ...@@ -525,7 +525,7 @@ func createClient() *api.Client {
initLog(logLevel, viper.GetString("log")) initLog(logLevel, viper.GetString("log"))
jww.INFO.Printf(Version()) jww.INFO.Printf(Version())
pass := viper.GetString("password") pass := parsePassword(viper.GetString("password"))
storeDir := viper.GetString("session") storeDir := viper.GetString("session")
regCode := viper.GetString("regcode") regCode := viper.GetString("regcode")
precannedID := viper.GetUint("sendid") precannedID := viper.GetUint("sendid")
...@@ -544,17 +544,17 @@ func createClient() *api.Client { ...@@ -544,17 +544,17 @@ func createClient() *api.Client {
if precannedID != 0 { if precannedID != 0 {
err = api.NewPrecannedClient(precannedID, err = api.NewPrecannedClient(precannedID,
string(ndfJSON), storeDir, []byte(pass)) string(ndfJSON), storeDir, pass)
} else if protoUserPath != "" { } else if protoUserPath != "" {
protoUserJson, err := utils.ReadFile(protoUserPath) protoUserJson, err := utils.ReadFile(protoUserPath)
if err != nil { if err != nil {
jww.FATAL.Panicf("%v", err) jww.FATAL.Panicf("%v", err)
} }
err = api.NewProtoClient_Unsafe(string(ndfJSON), storeDir, err = api.NewProtoClient_Unsafe(string(ndfJSON), storeDir,
[]byte(pass), protoUserJson) pass, protoUserJson)
} else if userIDprefix != "" { } else if userIDprefix != "" {
err = api.NewVanityClient(string(ndfJSON), storeDir, err = api.NewVanityClient(string(ndfJSON), storeDir,
[]byte(pass), regCode, userIDprefix) pass, regCode, userIDprefix)
} else if backupPath != "" { } else if backupPath != "" {
b, backupFile := loadBackup(backupPath, string(backupPass)) b, backupFile := loadBackup(backupPath, string(backupPass))
...@@ -573,7 +573,7 @@ func createClient() *api.Client { ...@@ -573,7 +573,7 @@ func createClient() *api.Client {
// Construct client from backup data // Construct client from backup data
backupIdList, _, err := api.NewClientFromBackup(string(ndfJSON), storeDir, backupIdList, _, err := api.NewClientFromBackup(string(ndfJSON), storeDir,
[]byte(pass), backupPass, backupFile) pass, backupPass, backupFile)
backupIdListPath := viper.GetString("backupIdList") backupIdListPath := viper.GetString("backupIdList")
if backupIdListPath != "" { if backupIdListPath != "" {
...@@ -593,7 +593,7 @@ func createClient() *api.Client { ...@@ -593,7 +593,7 @@ func createClient() *api.Client {
} else { } else {
err = api.NewClient(string(ndfJSON), storeDir, err = api.NewClient(string(ndfJSON), storeDir,
[]byte(pass), regCode) pass, regCode)
} }
if err != nil { if err != nil {
...@@ -612,7 +612,7 @@ func createClient() *api.Client { ...@@ -612,7 +612,7 @@ func createClient() *api.Client {
netParams.ForceMessagePickupRetry = viper.GetBool("forceMessagePickupRetry") netParams.ForceMessagePickupRetry = viper.GetBool("forceMessagePickupRetry")
netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking") netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking")
client, err := api.OpenClient(storeDir, []byte(pass), netParams) client, err := api.OpenClient(storeDir, pass, netParams)
if err != nil { if err != nil {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
...@@ -622,7 +622,7 @@ func createClient() *api.Client { ...@@ -622,7 +622,7 @@ func createClient() *api.Client {
func initClient() *api.Client { func initClient() *api.Client {
createClient() createClient()
pass := viper.GetString("password") pass := parsePassword(viper.GetString("password"))
storeDir := viper.GetString("session") storeDir := viper.GetString("session")
jww.DEBUG.Printf("sessionDur: %v", storeDir) jww.DEBUG.Printf("sessionDur: %v", storeDir)
netParams := params.GetDefaultNetwork() netParams := params.GetDefaultNetwork()
...@@ -642,7 +642,7 @@ func initClient() *api.Client { ...@@ -642,7 +642,7 @@ func initClient() *api.Client {
netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking") netParams.VerboseRoundTracking = viper.GetBool("verboseRoundTracking")
// load the client // load the client
client, err := api.Login(storeDir, []byte(pass), netParams) client, err := api.Login(storeDir, pass, netParams)
if err != nil { if err != nil {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
...@@ -853,6 +853,16 @@ func getPrecanID(recipientID *id.ID) uint { ...@@ -853,6 +853,16 @@ func getPrecanID(recipientID *id.ID) uint {
return uint(recipientID.Bytes()[7]) return uint(recipientID.Bytes()[7])
} }
func parsePassword(pwStr string) []byte {
if strings.HasPrefix(pwStr, "0x") {
return getPWFromHexString(pwStr[2:])
} else if strings.HasPrefix(pwStr, "b64:") {
return getPWFromb64String(pwStr[4:])
} else {
return []byte(pwStr)
}
}
func parseRecipient(idStr string) (*id.ID, bool) { func parseRecipient(idStr string) (*id.ID, bool) {
if idStr == "0" { if idStr == "0" {
return nil, false return nil, false
...@@ -905,6 +915,23 @@ func getUIDFromb64String(idStr string) *id.ID { ...@@ -905,6 +915,23 @@ func getUIDFromb64String(idStr string) *id.ID {
return ID return ID
} }
func getPWFromHexString(pwStr string) []byte {
pwBytes, err := hex.DecodeString(fmt.Sprintf("%0*d%s",
66-len(pwStr), 0, pwStr))
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return pwBytes
}
func getPWFromb64String(pwStr string) []byte {
pwBytes, err := base64.StdEncoding.DecodeString(pwStr)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return pwBytes
}
func getUIDFromString(idStr string) *id.ID { func getUIDFromString(idStr string) *id.ID {
idInt, err := strconv.Atoi(idStr) idInt, err := strconv.Atoi(idStr)
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment