adc: working PID/CID login

--HG--
branch : adc
This commit is contained in:
mappu 2017-11-26 14:01:46 +13:00
parent 3dc4ede0d8
commit b1c6a5f56a
2 changed files with 8 additions and 15 deletions

View File

@ -60,32 +60,18 @@ func NewAdcProtocol(hc *HubConnection) Protocol {
func (this *AdcProtocol) pid2cid(pid_base32 string) (string, error) {
/*
Generate random data and store it in PID_raw, then;
PID = Base32( PID_raw )
CID = Base32( Hash( PID_raw ) )
For GPA/PAS, assuming that '12345' is the random data supplied in GPA, then;
PAS = Base32( Hash( password + '12345' ) )
*/
pid_raw, err := base32.StdEncoding.DecodeString(pid_base32 + "=")
if err != nil {
return "", err
}
cid_raw, err := TTH(string(pid_raw))
if err != nil {
return "", err
}
cid_raw := Tiger(string(pid_raw))
cid_base32 := Base32(cid_raw)
return cid_base32, nil
}
func (this *AdcProtocol) ProcessCommand(msg string) {
this.hc.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: msg})
if len(msg) == 0 {
return
@ -168,6 +154,7 @@ func (this *AdcProtocol) ProcessCommand(msg string) {
//
default:
this.hc.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: msg})
this.malformed(parts)
}
}

6
tth.go
View File

@ -33,3 +33,9 @@ func TTH(input string) ([]byte, error) {
leafHash.Write([]byte("\x00" + input))
return leafHash.Sum(nil), nil
}
func Tiger(input string) []byte {
leafHash := tiger.New()
leafHash.Write([]byte(input))
return leafHash.Sum(nil)
}