Class: Packages::Debian::SignDistributionService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/debian/sign_distribution_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(distribution, content, detach: false) ⇒ SignDistributionService

Returns a new instance of SignDistributionService.



8
9
10
11
12
# File 'app/services/packages/debian/sign_distribution_service.rb', line 8

def initialize(distribution, content, detach: false)
  @distribution = distribution
  @content = content
  @detach = detach
end

Instance Method Details

#executeObject

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/packages/debian/sign_distribution_service.rb', line 14

def execute
  raise ArgumentError, 'distribution key is missing' unless @distribution.key

  sig_mode = GPGME::GPGME_SIG_MODE_CLEAR

  sig_mode = GPGME::GPGME_SIG_MODE_DETACH if @detach

  Gitlab::Gpg.using_tmp_keychain do
    GPGME::Ctx.new(
      armor: true,
      offline: true,
      pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK,
      password: @distribution.key.passphrase
    ) do |ctx|
      ctx.import(GPGME::Data.from_str(@distribution.key.public_key))
      ctx.import(GPGME::Data.from_str(@distribution.key.private_key))
      signature = GPGME::Data.new
      ctx.sign(GPGME::Data.from_str(@content), signature, sig_mode)
      signature.to_s
    end
  end
end