Skip to content

Commit

Permalink
service: Update keys package
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Mar 7, 2020
1 parent 359d684 commit 207b50d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 38 deletions.
3 changes: 0 additions & 3 deletions go.mod
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ require (
github.com/keys-pub/keysd/service v0.0.0-20200220194145-a8f03c5a1979
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.4.0
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 // indirect
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb // indirect
google.golang.org/grpc v1.27.0 // indirect
)

replace github.com/keys-pub/keysd/service => ./service
Expand Down
37 changes: 37 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ github.com/gabriel/go-keychain v0.0.0-20191220021328-378d9d7f4318 h1:1tHNxPJ/VcW
github.com/gabriel/go-keychain v0.0.0-20191220021328-378d9d7f4318/go.mod h1:plHH54j7iaX3vBD45GLILwTm6Q0BUNIdnzo67oC+T4M=
github.com/gabriel/goleveldb-encrypted v0.0.0-20191220210737-4aefa2aa0d62 h1:J9RlCExZJpgMm1ow0D2VpfX4GyviScCD3qhzO7/RU3A=
github.com/gabriel/goleveldb-encrypted v0.0.0-20191220210737-4aefa2aa0d62/go.mod h1:yzdsA0Rl2P3t/NTd92KjRsblTlZwsBiTsBRSskVG5l4=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
Expand All @@ -32,6 +35,9 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand All @@ -41,25 +47,43 @@ github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 h1:0IKlLyQ3Hs9nDaiK5cSHAGmcQEIC8l2Ts1u6x5Dfrqg=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/keybase/go-codec v0.0.0-20180928230036-164397562123 h1:yg56lYPqh9suJepqxOMd/liFgU/x+maRPiB30JNYykM=
github.com/keybase/go-codec v0.0.0-20180928230036-164397562123/go.mod h1:r/eVVWCngg6TsFV/3HuS9sWhDkAzGG8mXhiuYA+Z/20=
github.com/keybase/go-keychain v0.0.0-20191220220820-f65a47cbe0b1 h1:Lk38J60jgB05LTkSEElUXe49VEzWMNrPyPFf2vhKM1k=
github.com/keybase/go-keychain v0.0.0-20191220220820-f65a47cbe0b1/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
github.com/keybase/go-keychain v0.0.0-20200218013740-86d4642e4ce2 h1:1XZArHAPddaXKbg51etNbCjkNUkKgSa0s8dSz2LYB2g=
github.com/keybase/go-keychain v0.0.0-20200218013740-86d4642e4ce2/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
github.com/keybase/saltpack v0.0.0-20190828020936-3f47e8e2e6ec h1:ejQ18jEAjyiFen49m7h8x46kzC3heD/HbUiOPzBLVWg=
github.com/keybase/saltpack v0.0.0-20190828020936-3f47e8e2e6ec/go.mod h1:loEJH62iafRcA8ZYlUEq9WgJh/Z9BHdHHfAmxzacQng=
github.com/keybase/saltpack v0.0.0-20200228190633-d75baa96bffb h1:+AxJjayBs1yJrAddiOyvj7EjuN7ag1gl9QFszNTQX2M=
github.com/keybase/saltpack v0.0.0-20200228190633-d75baa96bffb/go.mod h1:loEJH62iafRcA8ZYlUEq9WgJh/Z9BHdHHfAmxzacQng=
github.com/keys-pub/keys v0.0.0-20200107200405-d846fd9e9499/go.mod h1:aHuCWPRJIO/FTUGpfFYE4BIqsWWTJ37Cp83aCMyu2fE=
github.com/keys-pub/keys v0.0.0-20200124060448-34fed9f6ffa9/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200223202242-70e1f1ef5e5f h1:fAC4Fny/niAbMq08jP5Mgg9hsB8r5NvISwjQrPYHh5A=
github.com/keys-pub/keys v0.0.0-20200223202242-70e1f1ef5e5f/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200302194536-8d981e7bb498 h1:AvtDLDZrenO73R2+FDzDqxRnWPITLnoNfi0byI5swgI=
github.com/keys-pub/keys v0.0.0-20200302194536-8d981e7bb498/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200306031145-ead068a10f45/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200306033554-02897e0a5bbe h1:tbw+R+PxU3YRlJ1zElASMKDf443I/ZiSiyA8qM7uc0k=
github.com/keys-pub/keys v0.0.0-20200306033554-02897e0a5bbe/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200307201134-33be20ddd0cc h1:6fdkYC3lpsdbioXH9s8zqQLvKK+CJdV1nrE374akj8g=
github.com/keys-pub/keys v0.0.0-20200307201134-33be20ddd0cc/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keysd/db v0.0.0-20200110200550-f472e79d2ba3 h1:D0h6bAO2HKg+SNU1VXa3IEu88MoaN2v5p7u1QDoYvEs=
github.com/keys-pub/keysd/db v0.0.0-20200110200550-f472e79d2ba3/go.mod h1:AB5JqGVXFwlbVGybCDbjni0rsFKNOuvykMvHqmIAEL8=
github.com/keys-pub/keysd/db v0.0.0-20200306174951-faa8a8074ae0 h1:TFFBpeyquDirpp6bCljXYToMvT+VMcvg9ZKFLKWb/ak=
github.com/keys-pub/keysd/db v0.0.0-20200306174951-faa8a8074ae0/go.mod h1:ztOikSIUWOyO6cjrSAZLdz5elQW1MXLLWTcmAKeo2cc=
github.com/keys-pub/keysd/http/api v0.0.0-20200223203725-9c5a5d442011 h1:cbemaD+yWU1fnuecmjAZhsYu2E7X/dGG0DiC2lo/C20=
github.com/keys-pub/keysd/http/api v0.0.0-20200223203725-9c5a5d442011/go.mod h1:oCloF/zhufOxDjykCl9bb1VjDHBQL4mljs5yz21p9/4=
github.com/keys-pub/keysd/http/api v0.0.0-20200306174951-faa8a8074ae0 h1:t1ajSVA+hlvFhnTNI3ohYbo1DPgHO1xZu4bWAOTMHfU=
github.com/keys-pub/keysd/http/api v0.0.0-20200306174951-faa8a8074ae0/go.mod h1:oCloF/zhufOxDjykCl9bb1VjDHBQL4mljs5yz21p9/4=
github.com/keys-pub/keysd/http/client v0.0.0-20200223204014-135c03e7b2d3 h1:xXCZqUkAzm0SzQ/GkH3gi6CuTf5BB+YL0YHIfLVK+G8=
github.com/keys-pub/keysd/http/client v0.0.0-20200223204014-135c03e7b2d3/go.mod h1:vB/t/vL+/XssB4dZyPLM0fQ5BLf0gmDM0YcrhJUyXu8=
github.com/keys-pub/keysd/http/client v0.0.0-20200306174951-faa8a8074ae0 h1:N7cF9CmU7x6icZr52NYwKtnZR625dNks3RFocw4m2rI=
github.com/keys-pub/keysd/http/client v0.0.0-20200306174951-faa8a8074ae0/go.mod h1:A2cF+eG+S5n9OANlTjXyLJbJqjK8sC2oLsSXXKQil6Q=
github.com/keys-pub/keysd/http/server v0.0.0-20200223203834-3dc7040c6558 h1:J1+5mS8vTI3KxOH6quLqZjdVcRzV061V6umb997vtOU=
github.com/keys-pub/keysd/http/server v0.0.0-20200223203834-3dc7040c6558/go.mod h1:hj7RqWuhjx+wn6hFPyA28QBZloZ/yhfvNdsRlW5gcTc=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand All @@ -68,6 +92,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -88,6 +113,8 @@ github.com/mercari/go-grpc-interceptor v0.0.0-20180110035004-b8ad3827e82a h1:of7
github.com/mercari/go-grpc-interceptor v0.0.0-20180110035004-b8ad3827e82a/go.mod h1:B+BeaFWaJ5nYIsMbxZVFEcR9wgwrySKSvQeUsdT4RSw=
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b h1:9+ke9YJ9KGWw5ANXK6ozjoK47uI3uNbXv4YVINBnGm8=
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.9.0 h1:SZjF721BByVj8QH636/8S2DnX4n0Re3SteMmw3N+tzc=
Expand Down Expand Up @@ -142,6 +169,8 @@ golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand All @@ -156,6 +185,8 @@ golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a h1:+HHJiFUXVOIS9mr1ThqkQD1N8
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -177,6 +208,8 @@ golang.org/x/sys v0.0.0-20200121082415-34d275377bf9 h1:N19i1HjUnR7TF7rMt8O4p3dLv
golang.org/x/sys v0.0.0-20200121082415-34d275377bf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -195,12 +228,16 @@ google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f h1:0RYv5T9ZdroAqqf
google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb h1:ADPHZzpzM4tk4V4S5cnCrr5SwzvlrPRmqqCuJDB8UTs=
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200306153348-d950eab6f860 h1:QmnwU8dKvY8c/vZikd2jhBNwrrGS5qeyK/2Aeeh9Grk=
google.golang.org/genproto v0.0.0-20200306153348-d950eab6f860/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
78 changes: 55 additions & 23 deletions service/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,57 @@ import (
"google.golang.org/grpc"
)

func (s *service) decryptSender(ctx context.Context, kid keys.ID, mode EncryptMode) (*Key, error) {
func (s *service) findSender(ctx context.Context, kid keys.ID) (*Key, error) {
if kid == "" {
logger.Infof("No decrypt sender")
return nil, nil
}
// If EncryptV2 check the kid.
if mode == EncryptV2 {
k, err := s.checkSenderID(kid)
if err != nil {
return nil, err
}
kid = k
k, err := s.convertX25519ID(kid)
if err != nil {
return nil, err
}
kid = k
return s.loadKey(ctx, kid)
}

// Decrypt (RPC) data.
func (s *service) Decrypt(ctx context.Context, req *DecryptRequest) (*DecryptResponse, error) {
var decrypted []byte
var kid keys.ID
var err error
sp := saltpack.NewSaltpack(s.ks)

mode := req.Mode
if mode == DefaultEncryptMode {
mode = EncryptV2
}

var decrypted []byte
var kid keys.ID
var err error
switch mode {
case EncryptV2:
var sender *keys.X25519PublicKey
if req.Armored {
decrypted, kid, err = sp.DecryptArmored(string(req.Data))
decrypted, sender, err = sp.DecryptArmored(string(req.Data))
if sender != nil {
kid = sender.ID()
}
} else {
decrypted, kid, err = sp.Decrypt(req.Data)
decrypted, sender, err = sp.Decrypt(req.Data)
if sender != nil {
kid = sender.ID()
}
}
case SigncryptV1:
var sender *keys.EdX25519PublicKey
if req.Armored {
decrypted, kid, err = sp.SigncryptArmoredOpen(string(req.Data))
decrypted, sender, err = sp.SigncryptArmoredOpen(string(req.Data))
if sender != nil {
kid = sender.ID()
}
} else {
decrypted, kid, err = sp.SigncryptOpen(req.Data)
decrypted, sender, err = sp.SigncryptOpen(req.Data)
if sender != nil {
kid = sender.ID()
}
}
default:
return nil, errors.Errorf("unsupported mode %s", mode)
Expand All @@ -65,14 +76,14 @@ func (s *service) Decrypt(ctx context.Context, req *DecryptRequest) (*DecryptRes
return nil, err
}

sender, err := s.decryptSender(ctx, kid, mode)
senderKey, err := s.findSender(ctx, kid)
if err != nil {
return nil, err
}

return &DecryptResponse{
Data: decrypted,
Sender: sender,
Sender: senderKey,
}, nil
}

Expand Down Expand Up @@ -178,7 +189,7 @@ func (s *service) decryptStream(srv decryptStreamServer, mode EncryptMode, armor
return err
}

sender, err := s.decryptSender(srv.Context(), kid, mode)
sender, err := s.findSender(srv.Context(), kid)
if err != nil {
return err
}
Expand All @@ -195,20 +206,41 @@ func (s *service) decryptStream(srv decryptStreamServer, mode EncryptMode, armor

func (s *service) decryptReader(ctx context.Context, reader io.Reader, mode EncryptMode, armored bool) (io.Reader, keys.ID, error) {
sp := saltpack.NewSaltpack(s.ks)
var out io.Reader
var kid keys.ID
var err error
switch mode {
case DefaultEncryptMode, EncryptV2:
var sender *keys.X25519PublicKey
if armored {
return sp.NewDecryptArmoredStream(reader)
out, sender, err = sp.NewDecryptArmoredStream(reader)
if sender != nil {
kid = sender.ID()
}
} else {
out, sender, err = sp.NewDecryptStream(reader)
if sender != nil {
kid = sender.ID()
}
}
return sp.NewDecryptStream(reader)
case SigncryptV1:
var sender *keys.EdX25519PublicKey
if armored {
return sp.NewSigncryptArmoredOpenStream(reader)
out, sender, err = sp.NewSigncryptArmoredOpenStream(reader)
if sender != nil {
kid = sender.ID()
}
} else {
out, sender, err = sp.NewSigncryptOpenStream(reader)
if sender != nil {
kid = sender.ID()
}
}
return sp.NewSigncryptOpenStream(reader)
default:
return nil, "", errors.Errorf("unsupported mode %s", mode)
}

return out, kid, err
}

func (s *service) decryptWriteInOut(ctx context.Context, in string, out string, mode EncryptMode, armored bool) (*Key, error) {
Expand Down Expand Up @@ -254,7 +286,7 @@ func (s *service) decryptWriteInOut(ctx context.Context, in string, out string,
return nil, err
}

sender, err := s.decryptSender(ctx, kid, mode)
sender, err := s.findSender(ctx, kid)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/keybase/go-keychain v0.0.0-20200218013740-86d4642e4ce2 // indirect
github.com/keybase/saltpack v0.0.0-20200228190633-d75baa96bffb // indirect
github.com/keys-pub/keys v0.0.0-20200306033554-02897e0a5bbe
github.com/keys-pub/keys v0.0.0-20200307201134-33be20ddd0cc
github.com/keys-pub/keysd/db v0.0.0-20200306174951-faa8a8074ae0
github.com/keys-pub/keysd/http/api v0.0.0-20200306174951-faa8a8074ae0
github.com/keys-pub/keysd/http/client v0.0.0-20200306174951-faa8a8074ae0
Expand Down
2 changes: 2 additions & 0 deletions service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/keys-pub/keys v0.0.0-20200302194536-8d981e7bb498/go.mod h1:/uNDuQDL1k
github.com/keys-pub/keys v0.0.0-20200306031145-ead068a10f45/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200306033554-02897e0a5bbe h1:tbw+R+PxU3YRlJ1zElASMKDf443I/ZiSiyA8qM7uc0k=
github.com/keys-pub/keys v0.0.0-20200306033554-02897e0a5bbe/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keys v0.0.0-20200307201134-33be20ddd0cc h1:6fdkYC3lpsdbioXH9s8zqQLvKK+CJdV1nrE374akj8g=
github.com/keys-pub/keys v0.0.0-20200307201134-33be20ddd0cc/go.mod h1:/uNDuQDL1kCcJVsKMG2xLwUMS7zvoUrWL9k1OMZ7GZw=
github.com/keys-pub/keysd/db v0.0.0-20200110200550-f472e79d2ba3 h1:D0h6bAO2HKg+SNU1VXa3IEu88MoaN2v5p7u1QDoYvEs=
github.com/keys-pub/keysd/db v0.0.0-20200110200550-f472e79d2ba3/go.mod h1:AB5JqGVXFwlbVGybCDbjni0rsFKNOuvykMvHqmIAEL8=
github.com/keys-pub/keysd/db v0.0.0-20200306174951-faa8a8074ae0 h1:TFFBpeyquDirpp6bCljXYToMvT+VMcvg9ZKFLKWb/ak=
Expand Down
Loading

0 comments on commit 207b50d

Please sign in to comment.