Fix occur panic when invalid PublicKey parsing.

This commit is contained in:
Naoki Kosaka 2020-01-29 17:36:56 +09:00
parent 91e147ac0d
commit f90b6a85c0
3 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,10 @@ func (actor *Actor) RetrieveRemoteActor(url string, uaString string, cache *cach
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return errors.New(resp.Status)
}
data, _ := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(data, &actor)
if err != nil {

View File

@ -25,6 +25,9 @@ func ReadPrivateKeyRSAfromPath(path string) (*rsa.PrivateKey, error) {
func ReadPublicKeyRSAfromString(pemString string) (*rsa.PublicKey, error) {
pemByte := []byte(pemString)
decoded, _ := pem.Decode(pemByte)
defer func() {
recover()
}()
keyInterface, err := x509.ParsePKIXPublicKey(decoded.Bytes)
if err != nil {
fmt.Fprintln(os.Stderr, err)

View File

@ -33,6 +33,9 @@ func decodeActivity(request *http.Request) (*activitypub.Activity, *activitypub.
return nil, nil, nil, err
}
PubKey, err := keyloader.ReadPublicKeyRSAfromString(remoteActor.PublicKey.PublicKeyPem)
if PubKey == nil {
return nil, nil, nil, errors.New("Failed parse PublicKey from string")
}
if err != nil {
return nil, nil, nil, err
}