New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79093


Ignore:
Timestamp:
06/01/11 21:32:01 (4 years ago)
Author:
jmr@…
Message:

add support for sync and selfupdate via rsync of tarballs with detached signatures (work in progress)

Location:
trunk/base
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/portmgr/jobs/mprsyncup

    r79086 r79093  
    3939MKDIR="/bin/mkdir" 
    4040LN="/bin/ln" 
     41TAR="/usr/bin/tar" 
     42OPENSSL="/usr/bin/openssl" 
    4143 
    4244# Paths we'll work on: 
     
    6567SVNURL=https://svn.macports.org/repository/macports 
    6668RELEASE_URL_FILE=config/RELEASE_URL 
     69 
     70# private key to use for signing 
     71# XXX set real path 
     72PRIVKEY="" 
    6773 
    6874# cleanup up the working copy if it is locked 
     
    146152    ${RM} -rf dports && ${LN} -s ../release/ports dports 
    147153fi 
     154 
     155# generate and sign tarballs of base and dports 
     156# the signature always needs to match, so we try to make this look atomic to 
     157# clients by switching a symlink target 
     158 
     159TAR_CURDIR=${RSYNCROOT}/release/tarballs_current 
     160${MKDIR} -p ${TAR_CURDIR} 
     161cp -pR ${TAR_CURDIR} ${RSYNCROOT}/release/tarballs_old 
     162${LN} -sf tarballs_old ${RSYNCROOT}/release/tarballs 
     163${TAR} -cf ${TAR_CURDIR}/base.tar ${RSYNCROOT}/release/base 
     164${TAR} -cf ${TAR_CURDIR}/ports.tar --exclude 'PortIndex*' ${RSYNCROOT}/release/ports 
     165cp -pR ${RSYNCROOT}/release/ports/PortIndex_* ${TAR_CURDIR} 
     166# XXX needs PRIVKEY to be set above 
     167#${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${TAR_CURDIR}/base.tar.rmd160 ${TAR_CURDIR}/base.tar 
     168#${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${TAR_CURDIR}/ports.tar.rmd160 ${TAR_CURDIR}/ports.tar 
     169for index in ${TAR_CURDIR}/PortIndex_*/PortIndex; do 
     170    #${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${index}.rmd160 ${index} 
     171done 
     172${LN} -sf tarballs_current ${RSYNCROOT}/release/tarballs 
     173${RM} -rf ${RSYNCROOT}/release/tarballs_old 
  • trunk/base/src/macports1.0/macports.tcl

    r79070 r79093  
    18611861    upvar $extension myextension 
    18621862 
    1863     if {[regexp {^(?:https?|ftp)://.+/(.+\.(tar\.gz|tar\.bz2))$} $url -> f e]} { 
     1863    if {[regexp {^(?:https?|ftp|rsync)://.+/(.+\.(tar\.gz|tar\.bz2|tar))$} $url -> f e]} { 
    18641864        set myfilename $f 
    18651865        set myextension $e 
     
    19051905    global macports::sources macports::portdbpath macports::rsync_options tcl_platform 
    19061906    global macports::portverbose 
    1907     global macports::autoconf::rsync_path 
     1907    global macports::autoconf::rsync_path macports::autoconf::tar_path macports::autoconf::openssl_path 
    19081908    array set options $optionslist 
    19091909 
     
    19571957                set indexfile [macports::getindex $source] 
    19581958                set destdir [file dirname $indexfile] 
     1959                set is_tarball [_source_is_snapshot $source] 
    19591960                file mkdir $destdir 
    1960                 # Keep rsync happy with a trailing slash 
    1961                 if {[string index $source end] != "/"} { 
    1962                     append source "/" 
    1963                 } 
    1964                 # don't sync PortIndex yet; we grab the platform specific one afterwards 
    1965                 set exclude_option "'--exclude=/PortIndex*'" 
     1961 
     1962                if {$is_tarball} { 
     1963                    set exclude_option "" 
     1964                    # need to do a few things before replacing the ports tree in this case 
     1965                    set destdir [file dirname $destdir] 
     1966                } else { 
     1967                    # Keep rsync happy with a trailing slash 
     1968                    if {[string index $source end] != "/"} { 
     1969                        append source "/" 
     1970                    } 
     1971                    # don't sync PortIndex yet; we grab the platform specific one afterwards 
     1972                    set exclude_option "'--exclude=/PortIndex*'" 
     1973                } 
    19661974                # Do rsync fetch 
    19671975                set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source} ${destdir}" 
     
    19721980                    continue 
    19731981                } 
     1982 
     1983                if {$is_tarball} { 
     1984                    # verify signature for tarball 
     1985                    global macports::archivefetch_pubkeys 
     1986                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source}.rmd160 ${destdir}" 
     1987                    ui_debug $rsync_commandline 
     1988                    if {[catch {system $rsync_commandline}]} { 
     1989                        ui_error "Synchronization of the ports tree signature failed doing rsync" 
     1990                        incr numfailed 
     1991                        continue 
     1992                    } 
     1993                    set tarball "${destdir}/[file tail $source]" 
     1994                    set signature "${tarball}.rmd160" 
     1995                    set openssl [findBinary openssl $macports::autoconf::openssl_path] 
     1996                    set verified 0 
     1997                    foreach pubkey ${macports::archivefetch_pubkeys} { 
     1998                        if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} { 
     1999                            set verified 1 
     2000                            ui_debug "successful verification with key $pubkey" 
     2001                            break 
     2002                        } else { 
     2003                            ui_debug "failed verification with key $pubkey" 
     2004                            ui_debug "openssl output: $result" 
     2005                        } 
     2006                    } 
     2007                    if {!$verified} { 
     2008                        ui_error "Failed to verify signature for ports tree!" 
     2009                        incr numfailed 
     2010                        continue 
     2011                    } 
     2012 
     2013                    # extract tarball and move into place 
     2014                    set tar [macports::findBinary tar $macports::autoconf::tar_path] 
     2015                    file mkdir ${destdir}/tmp 
     2016                    set tar_cmd "$tar -C ${destdir}/tmp -xf ${tarball}" 
     2017                    ui_debug $tar_cmd 
     2018                    if {[catch {system $tar_cmd}]} { 
     2019                        ui_error "Failed to extract ports tree from tarball!" 
     2020                        incr numfailed 
     2021                        continue 
     2022                    } 
     2023                    # save the local PortIndex data 
     2024                    if {[file isfile $indexfile]} { 
     2025                        file rename -force $indexfile ${destdir}/tmp/ports/ 
     2026                        if {[file isfile ${indexfile}.quick]} { 
     2027                            file rename -force ${indexfile}.quick ${destdir}/tmp/ports/ 
     2028                        } 
     2029                    } 
     2030                    file delete -force ${destdir}/ports 
     2031                    file rename ${destdir}/tmp/ports ${destdir}/ports 
     2032                    file delete -force ${destdir}/tmp 
     2033                } 
     2034 
    19742035                # now sync the index if the local file is missing or older than a day 
    19752036                if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400} { 
     2037                    if {$is_tarball} { 
     2038                        # chop ports.tar off the end 
     2039                        set source [string range $source 0 end-[string length [file tail $source]]] 
     2040                    } 
    19762041                    set remote_indexfile "${source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex" 
    19772042                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} $remote_indexfile ${destdir}" 
     
    19802045                        ui_debug "Synchronization of the PortIndex failed doing rsync" 
    19812046                    } else { 
    1982                         mports_generate_quickindex $indexfile 
     2047                        set ok 1 
     2048                        if {$is_tarball} { 
     2049                            set ok 0 
     2050                            # verify signature for PortIndex 
     2051                            set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${remote_indexfile}.rmd160 ${destdir}" 
     2052                            ui_debug $rsync_commandline 
     2053                            if {![catch {system $rsync_commandline}]} { 
     2054                                foreach pubkey ${macports::archivefetch_pubkeys} { 
     2055                                    if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature ${destdir}/PortIndex.rmd160 ${destdir}/PortIndex} result]} { 
     2056                                        set ok 1 
     2057                                        ui_debug "successful verification with key $pubkey" 
     2058                                        break 
     2059                                    } else { 
     2060                                        ui_debug "failed verification with key $pubkey" 
     2061                                        ui_debug "openssl output: $result" 
     2062                                    } 
     2063                                } 
     2064                                if {$ok} { 
     2065                                    # move PortIndex into place 
     2066                                    file rename -force ${destdir}/PortIndex ${destdir}/ports/ 
     2067                                } 
     2068                            } 
     2069                        } 
     2070                        if {$ok} { 
     2071                            mports_generate_quickindex $indexfile 
     2072                        } 
    19832073                    } 
    19842074                } 
     
    27872877    global macports::prefix macports::portdbpath macports::libpath macports::rsync_server macports::rsync_dir macports::rsync_options 
    27882878    global macports::autoconf::macports_version macports::autoconf::rsync_path tcl_platform 
     2879    global macports::autoconf::openssl_path macports::autoconf::tar_path 
    27892880    array set options $optionslist 
    27902881     
     
    28032894    } 
    28042895 
     2896    # are we syncing a tarball? (implies detached signature) 
     2897    set is_tarball 0 
     2898    if {[string range ${rsync_dir} end-3 end] == ".tar"} { 
     2899        set is_tarball 1 
     2900        set mp_source_path [file join $portdbpath sources ${rsync_server} [file dirname ${rsync_dir}]] 
     2901    } else { 
     2902        if {[string index $rsync_dir end] != "/"} { 
     2903            append rsync_dir "/" 
     2904        } 
     2905        set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}] 
     2906    } 
    28052907    # create the path to the to be downloaded sources if it doesn't exist 
    2806     set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}/] 
    28072908    if {![file exists $mp_source_path]} { 
    28082909        file mkdir $mp_source_path 
     
    28142915    if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } result ] } { 
    28152916       return -code error "Error synchronizing MacPorts sources: $result" 
     2917    } 
     2918 
     2919    if {$is_tarball} { 
     2920        # verify signature for tarball 
     2921        global macports::archivefetch_pubkeys 
     2922        if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path" } result ] } { 
     2923            return -code error "Error synchronizing MacPorts source signature: $result" 
     2924        } 
     2925        set openssl [findBinary openssl $macports::autoconf::openssl_path] 
     2926        set tarball "${mp_source_path}/[file tail $rsync_dir]" 
     2927        set signature "${tarball}.rmd160" 
     2928        set verified 0 
     2929        foreach pubkey ${macports::archivefetch_pubkeys} { 
     2930            if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} { 
     2931                set verified 1 
     2932                ui_debug "successful verification with key $pubkey" 
     2933                break 
     2934            } else { 
     2935                ui_debug "failed verification with key $pubkey" 
     2936                ui_debug "openssl output: $result" 
     2937            } 
     2938        } 
     2939        if {!$verified} { 
     2940            return -code error "Failed to verify signature for MacPorts source!" 
     2941        } 
     2942         
     2943        # extract tarball and move into place 
     2944        set tar [macports::findBinary tar $macports::autoconf::tar_path] 
     2945        file mkdir ${mp_source_path}/tmp 
     2946        set tar_cmd "$tar -C ${mp_source_path}/tmp -xf ${tarball}" 
     2947        ui_debug $tar_cmd 
     2948        if {[catch {system $tar_cmd}]} { 
     2949            return -code error "Failed to extract MacPorts sources from tarball!" 
     2950        } 
     2951        file delete -force ${mp_source_path}/base 
     2952        file rename ${mp_source_path}/tmp/base ${mp_source_path}/base 
     2953        file delete -force ${mp_source_path}/tmp 
     2954        # set the final extracted source path 
     2955        set mp_source_path ${mp_source_path}/base 
    28162956    } 
    28172957 
  • trunk/base/src/macports1.0/macports_autoconf.tcl.in

    r79009 r79093  
    4141    variable macportsuser "@RUNUSR@" 
    4242    variable open_path "@OPEN@" 
     43    variable openssl_path "@OPENSSL@" 
    4344    variable pax_path "@PAX@" 
    4445    variable rsync_path "@RSYNC@" 
Note: See TracChangeset for help on using the changeset viewer.