From 2eee956dc67e4780413051e83286d4080b7124b5 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Thu, 2 Jul 2020 12:49:04 +0200 Subject: [PATCH] Store hashes pk --- .../push_notification_server_persistence.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/protocol/push_notification_server/push_notification_server_persistence.go b/protocol/push_notification_server/push_notification_server_persistence.go index f23673bda..e7d65aaa9 100644 --- a/protocol/push_notification_server/push_notification_server_persistence.go +++ b/protocol/push_notification_server/push_notification_server_persistence.go @@ -29,7 +29,7 @@ func NewSQLitePersistence(db *sql.DB) Persistence { func (p *SQLitePersistence) GetPushNotificationRegistration(publicKey *ecdsa.PublicKey, installationID string) (*protobuf.PushNotificationRegistration, error) { var marshaledRegistration []byte - err := p.db.QueryRow(`SELECT registration FROM push_notification_server_registrations WHERE public_key = ? AND installation_id = ?`, crypto.CompressPubkey(publicKey), installationID).Scan(&marshaledRegistration) + err := p.db.QueryRow(`SELECT registration FROM push_notification_server_registrations WHERE public_key = ? AND installation_id = ?`, p.hashPublicKey(publicKey), installationID).Scan(&marshaledRegistration) if err == sql.ErrNoRows { return nil, nil @@ -46,17 +46,20 @@ func (p *SQLitePersistence) GetPushNotificationRegistration(publicKey *ecdsa.Pub } func (p *SQLitePersistence) SavePushNotificationRegistration(publicKey *ecdsa.PublicKey, registration *protobuf.PushNotificationRegistration) error { - compressedPublicKey := crypto.CompressPubkey(publicKey) marshaledRegistration, err := proto.Marshal(registration) if err != nil { return err } - _, err = p.db.Exec(`INSERT INTO push_notification_server_registrations (public_key, installation_id, version, registration) VALUES (?, ?, ?, ?)`, compressedPublicKey, registration.InstallationId, registration.Version, marshaledRegistration) + _, err = p.db.Exec(`INSERT INTO push_notification_server_registrations (public_key, installation_id, version, registration) VALUES (?, ?, ?, ?)`, p.hashPublicKey(publicKey), registration.InstallationId, registration.Version, marshaledRegistration) return err } func (p *SQLitePersistence) DeletePushNotificationRegistration(publicKey *ecdsa.PublicKey, installationID string) error { - _, err := p.db.Exec(`DELETE FROM push_notification_server_registrations WHERE public_key = ? AND installation_id = ?`, crypto.CompressPubkey(publicKey), installationID) + _, err := p.db.Exec(`DELETE FROM push_notification_server_registrations WHERE public_key = ? AND installation_id = ?`, p.hashPublicKey(publicKey), installationID) return err } + +func (p *SQLitePersistence) hashPublicKey(pk *ecdsa.PublicKey) []byte { + return shake256(crypto.CompressPubkey(pk)) +}