Skip to content

Instantly share code, notes, and snippets.

View zmajstor's full-sized avatar

Zoran Majstorovic zmajstor

View GitHub Profile
require 'openssl' unless defined? OpenSSL
# improved extraction and validation of the subjectAltName X509 extension for
# Universal Principal Name (UPN)
# Widely deployed Microsoft OtherName name form (OID 1.3.6.1.4.1.311.20.2.3)
# Format: user@domain
# Encoding: UTF-8
# Matching: case ignore
# e.g.
# otherName=1.3.6.1.4.1.311.20.2.3;UTF8:bobOtherAltName@example.com
require 'OpenSSL'
class KeyPair
attr_reader :key, :cert
def initialize serial, issuer=nil
@key = OpenSSL::PKey::RSA.new(1024)
@cert = OpenSSL::X509::Certificate.new
@cert.version = 2 # RFC 5280 - v3
@cert.serial = serial
@zmajstor
zmajstor / bootstrap_helper.rb
Created August 18, 2014 09:24
Bootstrap 3 rails helper for flash messages
module BootstrapHelper
# Bootstrap 3 helpers for Rails 4 Flash messages
# in Gemfile add line: gem 'bootstrap-sass', '~> 3.2.0'
# and <%= flash_messages %> in views/layouts/application.html.erb
# use in controllers: flash[:error] = 'Invalid email/password combination'
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
end
@zmajstor
zmajstor / san_cert.pem
Last active August 29, 2015 14:05
improved extraction and validation of the subjectAltName X509 extension; ASN1 decode for subjectAltName extension containing funny msUPN from Microsoft PKI (not decoded by out-of-the-box ruby OpenSSL library)
-----BEGIN CERTIFICATE-----
MIIExDCCA6ygAwIBAgITUgAACqTdV8IeZ2qIFgAAAAAKpDANBgkqhkiG9w0BAQUF
ADBJMRMwEQYKCZImiZPyLGQBGRYDbmV0MRYwFAYKCZImiZPyLGQBGRYGcHJvbWRt
MRowGAYDVQQDExFQcm9tZG1ORVRSb290Q0F2MTAeFw0xNDA4MTUxODIwNDBaFw0x
NTA4MTUxODIwNDBaMB0xGzAZBgNVBAMMElpvcmFuIE1hanN0b3JvdmnEhzCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM2z4QYHjTHNbSkl4UFF1E1X5zgG
TdVX5b6gpYjwlTpBNbFDNwAIePjJHZ/IMwpFpJzHU/G9chGx67D+RsfCkd1LHdnR
P0WOLKXsCImZIneAfvMt8gXDdeHzcXtNapgoIfjnAAZs4UN9Lxvd4KN2UpsSYKu+
jhRrmDE3vtedMLK7l1pnKSK6HCjch6zdnF9JytsdApGjcwKm4ubr/0y17XQvcrzl
21C0NRE77am/nR/3Jd3/qZjA7OT99KCjTx3OYXqZvU0s/4IEEBIyAWWFkxFQHlsE
# builder pattern in ruby
# inspired by https://github.com/tboyko/ios_config
# and http://blog.rubygeek.com/2009/11/24/builder-pattern-in-ruby/
module Payload
# provide base for building Payloads in Configuration Profile
class Base
def build
raise ArgumentError, "missing identifier" unless identifier
@zmajstor
zmajstor / _feather_editor.html.erb
Created August 2, 2014 10:06
rails-carrierwave-aviary image upload
<!-- Load Feather code -->
<!-- <script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script> -->
<script type="text/javascript" src="https://dme0ih8comzn4.cloudfront.net/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: 'API_KEY',
// apiKey: '<%= ENV['AVIARY_KEY'] %>',
apiVersion: 3,
class Payload
def general_payload
payload = Hash.new
payload['PayloadVersion'] = 1
payload['PayloadUUID'] = rand(10)
payload['PayloadOrganization'] = organization
payload
end
end

Keybase proof

I hereby claim:

  • I am zmajstor on github.
  • I am zmajstor (https://keybase.io/zmajstor) on keybase.
  • I have a public key whose fingerprint is 051D F53E 7747 101E 4A93 6AD8 C8CD 3A5E 8BFD BF3D

To claim this, I am signing this object:

@zmajstor
zmajstor / find_duplicates.rb
Created May 20, 2014 21:15
Find_by_SQL rows with duplicate attribute value
Device.find_by_sql "select udid, count(*) from devices group by udid having count(*) > 1"
@zmajstor
zmajstor / build_cn.rb
Created May 8, 2014 11:10
build string based on input strings and regex
# input parameters (from LDAP or device attributes SERIAL, UDID) ...
param1 = "abcdefgh12345678"
param2 = "qwertyui09876543"
param3 = "asdfghjkl@zxcvbnml"
# take first 5 non-whitespace character
regex1 = /^\S{5}/
# take last 4 non-whitespace character
regex2 = /\S{4}$/