bgul notes: encryption

Using GPG

Alice wants to send encrypted message to Bob. Bob needs to generate key pair and send public key to Alice.

Bob:

# first generate key
bob$ gpg --gen-key

# then see if your key was added to keyring
bob$ gpg --list-keys
/home/bob/.gnupg/pubring.gpg
------------------------------
pub  1024A/BBE5BA2A 2009-01-14 Bob (Bob's GPG key pair) 
sub  1024g/38681206 2001-01-14

# now, export your public key and send it via email to Alice
bob$ gpg --armor --export bob@bob.com > bobs_public.key 

Alice reads her email, and saves bobs_public.key to disk. Alice:

# import Bob's public key
alice$ gpg --import bobs_public.key

# optionally see fingerprint and add to trusted keys
alice$ gpg --edit-key bob@bob.com
> fpr
> sign
> quit

 # let's encrypt some secrets
alice$ gpg --out secrets_for_bob.pgp --encrypt secrets.txt 

Now Bob when receives secretsforbob.pgp can do:

bob$ gpg --out secrets.txt --decrypt secrets_for_bob.pgp

bob$ cat secrets.txt
I love you!

Encrypting hard disks / pendrives / SD cards

Excelent example here

Posted by Hubert Łępicki Wed, 14 Jan 2009 15:03:00 GMT


BGUL 2008/11/16: Subversion na serwerze KWI

Zgodnie z obietnic?, krtka notatka jak za?o?y? Subversion na serwerze KWI z dost?pem przez SSH.

# zalogowanie sie na serwer
$ ssh username@kwi.pb.bialystok.pl

$ mkdir repos
$ cd repos

# stworzenie repozytorium
$ svnadmin create repo1

$ logout
Connection to kwi.pb.bialystok.pl closed.

I teraz mo?emy stworzy? podstawow? struktur? katalogw repozytorium:

$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk -m "Tworze trunk"
$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/tags -m "Tworze tags"
$ svn mkdir svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/branches -m "Tworze branches"

Stworzmy jakis przykladowy projekt w C:

$ mkdir projekt
$ cd projekt
$ vim main.c 
# i wpisz jakas tresc
$ touch README.txt 
# pusty plik readme

Import projektu do repozytorium:

# b?d?c w katalogu projektu:
$ svn import . svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk -m "Poczatkowy import projektu"
Dodawanie       main.c
Dodawanie       README.txt
Zatwierdzona wersja 4.

$ cd ..
# usuwamy niepotrzebna poczatkowy katalog z projektem:
$ rm -rf projekt

# i pobieramy projekt z repozytorium
$ svn checkout svn+ssh://username@kwi.pb.bialystok.pl/home/username/repos/project1/trunk projekt
A    projekt/main.c
A    projekt/README.txt
Pobrano wersj? 4.

Voila! Mamy dzia?aj?ce repozytorium. Kilka komend do obs?ugi:

$ svn commit  .  -m "Wysylanie do repozytorium"
# pobieranie z repozytorium: 
$ svn up . 
# log:
$ svn log
# Dodawanie plikw/katalog? do repozytorium
$ svn add nowykatalog
# podobnie jak add mamy "rm"  do usuwania, "mv" do przenoszenia itd.

Posted by Hubert Łępicki Wed, 26 Nov 2008 20:20:00 GMT


BGUL Ruby in Linux example source code

This might be useful for these present at today’s BGUL meeting, but not only. Basically, I have demonstrated how to develop simple script useful for sysadmins, that checks if web pages are up and running, and stores results in MySQL database.

Additional cleanup, error handling and comments added (in Polish, sorry).

Full code is here

main.rb

#!/usr/bin/ruby
#
# G?wny plik programu
# utuchamianie:
# $ ruby main.rb
# lub
# $ ./main.rb

# Do??czamy nasze biblioteki
require 'config'
require 'site_test'

# i bibliotek? do obs?ugi MySQL
require 'mysql'

begin
  # Najpierw ??czymy si? z baz? danych
  connection = Mysql::init()
  # wpiszcie swoje dane poni?ej (has?o tu jest puste, ale jak trzeba to nie zapomnijcie)
  connection.connect("localhost", "root", "", "tester")

  for url in Config.instance.urls # w p?tli sprawd? wszystkie strony
    # przetestuj URL
    puts "Testuje... " +url
    test = SiteTest.new(url)
    puts Time.new.strftime('%Y-%m-%d %H:%M:%S')
    connection.query("INSERT into site_tests VALUES ('', '#{Time.new.strftime('%Y%m%d%H%M%S')}', '#{url}', '#{test.code}', '#{test.message}')")
  end

rescue Mysql::Error => e # odpowiednik sekcji "catch" z Javy/C++
  puts "Oops, mamy error bazy danych: "+e
ensure # wykonaj zawsze -> patrz "finally" w javie
  connection.close()
end

config.rb

require "yaml"
require "singleton"

# Daje dost?p do danych zapianych w pliku konfiguracyjnym
class Config
  include Singleton

  attr_reader :urls, :timeout

  def initialize
    # Pliki YAML przegl?da si? podobnie do plikw XML przy pomocy XPath
    options = YAML::parse( File.open( "configuration.yml" ) )
    @urls = options.select("/urls/*").collect { |el| el.value }
    @timeout = options.select("/timeout")[0].value.to_i # konwersja stringa do integera
  end
end

site_test.rb

require 'net/http'
require 'uri'
require 'config'

# Klasa ta przy inicjalizacji testuje dost?pno?? strony, zapisuj?c we w?a?ciwo?ciach "code" i "message" status
class SiteTest

  attr_accessor :code, :message

  def initialize(url) # konstruktor z parametrem
    begin
      adres = URI.parse(url)
      path = "/"
      path = adres.path if adres.path != ""
      req = Net::HTTP::Get.new(path)
      res = Net::HTTP.start(adres.host, adres.port) {|http|
        http.read_timeout = http.open_timeout = Config.instance.timeout
        http.request(req)
      }

      @code = res.code
      @message = res.message
    rescue Timeout::Error => e
      @code = 0
      @message = "Timeout of #{Config.instance.timeout} seconds exceeded"
    rescue SocketError =>e
      @code = -1 # tak oznaczmy sobie "inny b??d", np. nie ma takiego hosta
      @message = e.to_s
    end

  end
end
# To jest zwyk?y plik YAML
urls:
    - http://www.wp.pl
    - http://slashdot.org
    - http://gazeta.pl
    - http://bgul.org
    - http://microsoftruby.com

timeout: 10

Posted by Hubert Łępicki Wed, 29 Oct 2008 22:53:00 GMT


BGUL / JTeam meetings - 02.04.2008 and 09.04.2008 ][

Posted by Hubert Łępicki Wed, 09 Apr 2008 21:33:00 GMT


JTeam/Bgul Example rails 2.0 application

Posted by Hubert Łępicki Thu, 03 Apr 2008 21:36:00 GMT


BGUL / JTeam meetings - 02.04.2008 and 09.04.2008

This is announcement for our local Linux/Java community at Bialystok Technical University but… I’m a speaker at next two meetings of BGUL, together with JTeam. Subject - JRuby on Rails - I’ll try to prepare some cool examples of code that you might expect to appear on this blog this weekend / next week even before the first meeting.

Exactly when and where? This will appear on JTeam and/or BGUL web sites.

Everyone is invited!

Posted by Hubert Łępicki Fri, 28 Mar 2008 22:34:00 GMT