rpmutils

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 23 Imported by: 55

README

Go RPM Utils

go-rpmutils is a library written in go for parsing and extracting content from RPMs.

Overview

go-rpmutils provides a few interfaces for handling RPM packages. There is a highlevel Rpm struct that provides access to the RPM header and CPIO payload. The CPIO payload can be extracted to a filesystem location via the ExpandPayload function or through a Reader interface, similar to the tar implementation in the go standard library.

Example

func main() {
    f, err := os.Open("foo.rpm")
    if err != nil {
        panic(err)
    }

    // Parse the rpm
    rpm := rpmutils.ReadRpm(f)

    // Get the name, epoch, version, release, and arch
    nevra, err := rpm.Header.GetNEVRA()
    if err != nil {
        panic(err)
    }

    fmt.Printf("%s\n", nevra)

    // Reading the provides header
    provides, err := rpm.Header.GetStrings(rpmutils.PROVIDENAME)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Provides:\n")
    for _, p := range provides {
        fmt.Printf("%s", p)
    }
}

Contributing

  1. Read contributor agreement
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -a). Make sure to include a Signed-off-by line per the contributor agreement.
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

go-rpmutils is released under the Apache 2.0 license. See LICENSE.

Documentation

Index

Constants

View Source
const (
	// PGP Hash Algorithms
	PGPHASHALGO_MD5         = 1  // MD5
	PGPHASHALGO_SHA1        = 2  // SHA1
	PGPHASHALGO_RIPEMD160   = 3  // RIPEMD160
	PGPHASHALGO_MD2         = 5  // MD2
	PGPHASHALGO_TIGER192    = 6  // TIGER192
	PGPHASHALGO_HAVAL_5_160 = 7  // HAVAL-5-160
	PGPHASHALGO_SHA256      = 8  // SHA256
	PGPHASHALGO_SHA384      = 9  // SHA384
	PGPHASHALGO_SHA512      = 10 // SHA512
	PGPHASHALGO_SHA224      = 11 // SHA224
)
View Source
const (
	RPM_NULL_TYPE         = 0
	RPM_CHAR_TYPE         = 1
	RPM_INT8_TYPE         = 2
	RPM_INT16_TYPE        = 3
	RPM_INT32_TYPE        = 4
	RPM_INT64_TYPE        = 5
	RPM_STRING_TYPE       = 6
	RPM_BIN_TYPE          = 7
	RPM_STRING_ARRAY_TYPE = 8
	RPM_I18NSTRING_TYPE   = 9

	NAME              = 1000
	VERSION           = 1001
	RELEASE           = 1002
	EPOCH             = 1003
	SUMMARY           = 1004
	DESCRIPTION       = 1005
	BUILDTIME         = 1006
	BUILDHOST         = 1007
	SIZE              = 1009
	DISTRIBUTION      = 1010
	VENDOR            = 1011
	GIF               = 1012
	XPM               = 1013
	LICENSE           = 1014
	PACKAGER          = 1015
	GROUP             = 1016
	CHANGELOG         = 1017
	SOURCE            = 1018
	PATCH             = 1019
	URL               = 1020
	OS                = 1021
	ARCH              = 1022
	PREIN             = 1023
	POSTIN            = 1024
	PREUN             = 1025
	POSTUN            = 1026
	OLDFILENAMES      = 1027
	FILESIZES         = 1028
	FILEMODES         = 1030
	FILERDEVS         = 1033
	FILEMTIMES        = 1034
	FILEDIGESTS       = 1035 // AKA FILEMD5S
	FILELINKTOS       = 1036
	FILEFLAGS         = 1037 // bitmask: RPMFILE_* are bitmasks to interpret
	FILEUSERNAME      = 1039
	FILEGROUPNAME     = 1040
	ICON              = 1043
	SOURCERPM         = 1044
	FILEVERIFYFLAGS   = 1045 // bitmask: RPMVERIFY_* are bitmasks to interpret
	ARCHIVESIZE       = 1046
	PROVIDENAME       = 1047
	REQUIREFLAGS      = 1048
	REQUIRENAME       = 1049
	REQUIREVERSION    = 1050
	RPMVERSION        = 1064
	TRIGGERSCRIPTS    = 1065
	TRIGGERNAME       = 1066
	TRIGGERVERSION    = 1067
	TRIGGERFLAGS      = 1068 // bitmask: RPMSENSE_* are bitmasks to interpret
	TRIGGERINDEX      = 1069
	VERIFYSCRIPT      = 1079
	PREINPROG         = 1085
	POSTINPROG        = 1086
	PREUNPROG         = 1087
	POSTUNPROG        = 1088
	OBSOLETENAME      = 1090
	FILEDEVICES       = 1095
	FILEINODES        = 1096
	PROVIDEFLAGS      = 1112
	PROVIDEVERSION    = 1113
	OBSOLETEFLAGS     = 1114
	OBSOLETEVERSION   = 1115
	VERIFYSCRIPTPROG  = 1091
	TRIGGERSCRIPTPROG = 1092
	DIRINDEXES        = 1116
	BASENAMES         = 1117
	DIRNAMES          = 1118
	PAYLOADFORMAT     = 1124
	PAYLOADCOMPRESSOR = 1125
	FILECOLORS        = 1140
	// BLINK*, FLINK*, and TRIGGERPREIN included from SUSE fork of RPM
	BLINKPKGID   = 1164
	BLINKHDRID   = 1165
	BLINKNEVRA   = 1166
	FLINKPKGID   = 1167
	FLINKHDRID   = 1168
	FLINKNEVRA   = 1169
	TRIGGERPREIN = 1170

	LONGFILESIZES  = 5008
	LONGSIZE       = 5009
	FILECAPS       = 5010
	FILEDIGESTALGO = 5011
	BUGURL         = 5012
	VCS            = 5034
	ENCODING       = 5062

	SIG_BASE            = 256
	SIG_DSA             = SIG_BASE + 11 // DSA signature over header only
	SIG_RSA             = SIG_BASE + 12 // RSA signature over header only
	SIG_SHA1            = SIG_BASE + 13 // SHA1 over header only (hex)
	SIG_LONGSIZE        = SIG_BASE + 15 // header + compressed payload (uint64)
	SIG_LONGARCHIVESIZE = SIG_BASE + 15 // uncompressed payload bytes (uint64)

	SIG_SIZE          = _SIGHEADER_TAG_BASE + 1000 // Header + Payload size
	SIG_PGP           = _SIGHEADER_TAG_BASE + 1002 // Signature over header + payload
	SIG_MD5           = _SIGHEADER_TAG_BASE + 1004 // MD5SUM of header + payload
	SIG_GPG           = _SIGHEADER_TAG_BASE + 1005 // (same as SIG_PGP)
	SIG_PAYLOADSIZE   = _SIGHEADER_TAG_BASE + 1007 // uncompressed payload bytes (uint32)
	SIG_RESERVEDSPACE = _SIGHEADER_TAG_BASE + 1008 // blank space that can be replaced by a signature

	// FILEFLAGS bitmask elements:
	RPMFILE_NONE      = 0
	RPMFILE_CONFIG    = 1 << 0
	RPMFILE_DOC       = 1 << 1
	RPMFILE_ICON      = 1 << 2
	RPMFILE_MISSINGOK = 1 << 3
	RPMFILE_NOREPLACE = 1 << 4
	RPMFILE_SPECFILE  = 1 << 5
	RPMFILE_GHOST     = 1 << 6
	RPMFILE_LICENSE   = 1 << 7
	RPMFILE_README    = 1 << 8
	RPMFILE_EXCLUDE   = 1 << 9
	RPMFILE_UNPATCHED = 1 << 10
	RPMFILE_PUBKEY    = 1 << 11
	RPMFILE_POLICY    = 1 << 12

	// FILEVERIFYFLAGS bitmask elements:
	RPMVERIFY_NONE       = 0
	RPMVERIFY_MD5        = 1 << 0
	RPMVERIFY_FILEDIGEST = 1 << 0
	RPMVERIFY_FILESIZE   = 1 << 1
	RPMVERIFY_LINKTO     = 1 << 2
	RPMVERIFY_USER       = 1 << 3
	RPMVERIFY_GROUP      = 1 << 4
	RPMVERIFY_MTIME      = 1 << 5
	RPMVERIFY_MODE       = 1 << 6
	RPMVERIFY_RDEV       = 1 << 7
	RPMVERIFY_CAPS       = 1 << 8
	RPMVERIFY_CONTEXTS   = 1 << 15

	// TRIGGERFLAGS bitmask elements -- not all rpmsenseFlags make sense
	// in TRIGGERFLAGS
	RPMSENSE_ANY           = 0
	RPMSENSE_LESS          = 1 << 1
	RPMSENSE_GREATER       = 1 << 2
	RPMSENSE_EQUAL         = 1 << 3
	RPMSENSE_TRIGGERIN     = 1 << 16
	RPMSENSE_TRIGGERUN     = 1 << 17
	RPMSENSE_TRIGGERPOSTUN = 1 << 18
	RPMSENSE_TRIGGERPREIN  = 1 << 25

	// Header region tags
	RPMTAG_HEADERSIGNATURES = 62
	RPMTAG_HEADERIMMUTABLE  = 63
	RPMTAG_HEADERREGIONS    = 64
)

Variables

View Source
var (
	R_NONALNUMTILDE = regexp.MustCompile(`^([^a-zA-Z0-9~]*)(.*)$`)
	R_NUM           = regexp.MustCompile(`^([\d]+)(.*)$`)
	R_ALPHA         = regexp.MustCompile(`^([a-zA-Z]+)(.*)$`)
)

Functions

func GetFileAlgoName

func GetFileAlgoName(algo int) string

func NEVRAcmp

func NEVRAcmp(a NEVRA, b NEVRA) int

func Vercmp

func Vercmp(first, second string) int

func Verify

func Verify(stream io.Reader, knownKeys openpgp.EntityList) (header *RpmHeader, sigs []*Signature, err error)

Types

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	UserName() string
	GroupName() string
	Flags() int
	Mtime() int
	Digest() string
	Mode() int
	Linkname() string
	Device() int
	Inode() int
}

type NEVRA

type NEVRA struct {
	Name    string
	Epoch   string
	Version string
	Release string
	Arch    string
}

func (*NEVRA) String

func (nevra *NEVRA) String() string

type NEVRASlice

type NEVRASlice []NEVRA

func (NEVRASlice) Len

func (s NEVRASlice) Len() int

func (NEVRASlice) Less

func (s NEVRASlice) Less(i, j int) bool

func (NEVRASlice) Sort

func (s NEVRASlice) Sort()

func (NEVRASlice) Swap

func (s NEVRASlice) Swap(i, j int)

type NoSuchTagError

type NoSuchTagError struct {
	Tag int
}

func NewNoSuchTagError

func NewNoSuchTagError(tag int) NoSuchTagError

func (NoSuchTagError) Error

func (err NoSuchTagError) Error() string

type PayloadReader

type PayloadReader interface {
	Next() (FileInfo, error)
	Read([]byte) (int, error)
	IsLink() bool
}

type Rpm

type Rpm struct {
	Header *RpmHeader
	// contains filtered or unexported fields
}

func ReadRpm

func ReadRpm(f io.Reader) (*Rpm, error)

func (*Rpm) ExpandPayload

func (rpm *Rpm) ExpandPayload(dest string) error

func (*Rpm) PayloadReader

func (rpm *Rpm) PayloadReader() (*cpio.Reader, error)

func (*Rpm) PayloadReaderExtended

func (rpm *Rpm) PayloadReaderExtended() (PayloadReader, error)

type RpmHeader

type RpmHeader struct {
	// contains filtered or unexported fields
}

func ReadHeader

func ReadHeader(f io.Reader) (*RpmHeader, error)

func RewriteWithSignatures

func RewriteWithSignatures(infile *os.File, outpath string, sigPgp, sigRsa []byte) (*RpmHeader, error)

func SignRpmFile

func SignRpmFile(infile *os.File, outpath string, key *packet.PrivateKey, opts *SignatureOptions) (header *RpmHeader, err error)

func SignRpmStream

func SignRpmStream(stream io.Reader, key *packet.PrivateKey, opts *SignatureOptions) (header *RpmHeader, err error)

Read an RPM and sign it, returning the set of headers updated with the new signature.

func (*RpmHeader) DumpSignatureHeader

func (hdr *RpmHeader) DumpSignatureHeader(sameSize bool) ([]byte, error)

Dump the lead and signature header, optionally adding or changing padding to make it the same size as when it was originally read. Otherwise padding is removed to make it as small as possible.

func (*RpmHeader) Get

func (hdr *RpmHeader) Get(tag int) (interface{}, error)

func (*RpmHeader) GetBytes

func (hdr *RpmHeader) GetBytes(tag int) ([]byte, error)

func (*RpmHeader) GetFiles

func (hdr *RpmHeader) GetFiles() ([]FileInfo, error)

func (*RpmHeader) GetInt

func (hdr *RpmHeader) GetInt(tag int) (int, error)

func (*RpmHeader) GetInts

func (hdr *RpmHeader) GetInts(tag int) ([]int, error)

func (*RpmHeader) GetNEVRA

func (hdr *RpmHeader) GetNEVRA() (*NEVRA, error)

func (*RpmHeader) GetString

func (hdr *RpmHeader) GetString(tag int) (string, error)

func (*RpmHeader) GetStrings

func (hdr *RpmHeader) GetStrings(tag int) ([]string, error)

func (*RpmHeader) GetUint64Fallback

func (hdr *RpmHeader) GetUint64Fallback(intTag, longTag int) (uint64, error)

func (*RpmHeader) HasTag

func (hdr *RpmHeader) HasTag(tag int) bool

func (*RpmHeader) InstalledSize

func (hdr *RpmHeader) InstalledSize() (int64, error)

Return the approximate disk space needed to install the package

func (*RpmHeader) OriginalSignatureHeaderSize

func (hdr *RpmHeader) OriginalSignatureHeaderSize() int

func (*RpmHeader) PayloadSize

func (hdr *RpmHeader) PayloadSize() (int64, error)

Return the size of the uncompressed payload in bytes

type Signature

type Signature struct {
	Signer       *openpgp.Entity
	Hash         crypto.Hash
	CreationTime time.Time
	HeaderOnly   bool
	KeyId        uint64
	// contains filtered or unexported fields
}

type SignatureOptions

type SignatureOptions struct {
	Hash         crypto.Hash
	CreationTime time.Time
}

type VersionSlice

type VersionSlice []string

VersionSlice provides the Sort interface for sorting version strings.

func (VersionSlice) Len

func (vs VersionSlice) Len() int

Len is the number of elements in the collection.

func (VersionSlice) Less

func (vs VersionSlice) Less(i, j int) bool

Less reports wheather the element with index i should sort before the element with index j.

func (VersionSlice) Swap

func (vs VersionSlice) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Directories

Path Synopsis
pmpgp module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL