Debian Codegraph @

signers/apk/signer.go

raw symbols SCIP
1 //
2 // Copyright (c) SAS Institute Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 package apk
18
19 import (
20 "errors"
21 "io"
22
23 "github.com/sassoftware/relic/v7/lib/certloader"
24 "github.com/sassoftware/relic/v7/lib/magic"
25 "github.com/sassoftware/relic/v7/signers"
26 "github.com/sassoftware/relic/v7/signers/zipbased"
27 )
28
29 // Sign Android packages
30
31 var ApkSigner = &signers.Signer{
32 Name: "apk",
33 Magic: magic.FileTypeAPK,
34 CertTypes: signers.CertTypeX509,
35 Transform: zipbased.Transform,
36 Sign: sign,
37 Verify: verify,
38 }
39
40 const (
41 sigMagic = "APK Sig Block 42"
42 sigApkV2 = 0x7109871a
43 )
44
45 var (
46 errMalformed = errors.New("malformed APK signing block")
47 errTruncated = errors.New("truncated APK signing block sequence")
48 )
49
50 func init() {
51 signers.Register(ApkSigner)
52 }
53
54 func sign(r io.Reader, cert *certloader.Certificate, opts signers.SignOpts) ([]byte, error) {
55 digest, err := digestApkStream(r, opts.Hash)
56 if err != nil {
57 return nil, err
58 }
59 patchset, err := digest.Sign(cert)
60 if err != nil {
61 return nil, err
62 }
63 return opts.SetBinPatch(patchset)
64 }